I use FORTRAN 77 code to generate data (saved as filename.dat) of simple physics situations containing x-y co-ordinates like a projectile.
My data files usually have 2 or 3 columns like so:
1 1
2 2
3 3
4 4
5 5
I can plot (2d and 3d) using Gnuplot just fine but I want to animate the point and make it look like a real projectile on the graph and then save it as a .gif file.
I am new to bash scripts so please assume I do not know a single thing about scripts, if it involves using those.
Thanks!
Problem solved. This is the code I am using:
set terminal gif animate delay 100
set output 'output.gif'
stats 'data.dat' nooutput
set xrange [-0.5:1.5]
set yrange [-0.5:5.5]
do for [i=1:int(STATS_blocks)] {
plot 'data.dat' index (i-1) with circles
}
Gnuplot version 4.6 or higher is required for this to work. This code must be entered in gnuplot. This requires the data to be in the following format:
1 1
2 2
3 3
4 4
Related
I am plotting data with y-errorbars on a pdfcairo terminal and have a problem to properly size the data points:
plot "test.data" u ($6) : 10 : 11 with yerrorbars pt 7 ps 0.5 t
ps 1 gives too large a point and decreasing ps gives strange results. Interestingly, on a windows terminal everything looks ok, but the pdfcairo terminal makes problems. What is wrong?
Hmm. I see a problem also but I do not know what causes it.
Workaround
Plot the data twice, once to show the error bars and once to show the variable size points. Here is a screenshot of the pdf output using gnuplot 5.4.4
set term pdfcairo
set output 'yerrorbar.pdf'
set sample 51
set xrange [0:1]
set key left reverse
plot '+' using 1:1:(0.2) with yerrorbar lc 'blue' pt 7 ps 0, \
'+' using 1:1:1 with points lc 'blue' pt 7 ps variable
I'm an environmental engineer using TecPlot to plot come charts with some input data, let me explain my problem.
I'm studying the evolution of a river bed with a Fortran code which I wrote. As a output the code gives a detailed stratigraphy going some centimeters under the soils surface. Basically the output file looks like this:
0.03500000000 -0.18093000000 -0.17093000000 -0.16093000000 -0.15093000000 ...
0.10500000000 -0.18100000000 -0.17100000000 -0.16100000000 -0.15100000000 ...
0.17500000000 -0.18107000000 -0.17107000000 -0.16107000000 -0.15107000000 ...
0.24500000000 ...
and so on.
The first column is the x variable (horizontal evolution) and has 200 data.
The other columns are the evolution on the vertical coordinate.
So basically for each line we have, starting from the second colon, an horizontal line drawn thanks to 400 values.
For example if I plot the entire first column with the entire first row what I get is just a line on the plot.
For each time step my Fortran code create an output file which gives a plot with all the substrate lines.
What I want to do, and I really don't know how to do it, is animating this plots in order to have, for each time step of the animation, the ENTIRE plot with ALL THE LINES.
What I've done in TecPlot so far is:
1) import all the output files
2) put them in the XY Line plot of TecPlot using one zone for each output file I have (file 1 -> 1:ZONE001, file 2 -> 2:ZONE001, file 3 -> 3:ZONE001 and so on)
3) trying to turn them into contour plot (no results)
3.2) trying to animate them with XY Line plot animation (too bad, it animates every single line...)
I hope that I've been enough thorough to let you helping me.
I would appreciate each contribution and I thank You for each -even short, small- answer.
Best regards
Assuming you have already loaded the file, and have multiple zones. you can animate the mappings by Animate -> Mappings.., As far as
trying to animate them with XY Line plot animation (too bad, it animates every single line...)
is concerned, you need Map Skip value more than 1, to skip the mappings (lines). The animation can be saved as video or image sequences from the same dialogue box, by pressing the small video button besides the play rewind and forward buttons enter image description here
Ok, I know this question might sound silly, but I cannot find out why the demo from the gnuplot official website (you can see an example on the left hand side in the picture below) looks different (and much nicer) than what I get from running the same demo on my machine (on a wxt terminal).
Is there a configuration file (something like a ~/.gnuplotrc) where a theme has been specified? If so, does anyone know what theme has been used here?
Here you have an image where you can compare the website and the locally-made versions
Moreover, just an off topic curiosity, is anyone using gnuplot seriously, or it's basically used to plot simple batch plots and for Octave?
It is very likely that the person who made the demo (likely Ethan Merritt) has defined his/her own set of default line colors, which are reflected in the demo images. You can do this yourself (see help set linetype). Example from gnuplot e-mail list:
# Ethan A Merritt - my preference for gnuplot colors
# 2 3 4 5 6 8 are borrowed from the colors_podo set
#
set linetype 1 lc rgb "dark-violet" lw 1
set linetype 2 lc rgb "#009e73" lw 1
set linetype 3 lc rgb "#56b4e9" lw 1
set linetype 4 lc rgb "#e69f00" lw 1
set linetype 5 lc rgb "#f0e442" lw 1
set linetype 6 lc rgb "#0072b2" lw 1
set linetype 7 lc rgb "#e51e10" lw 1
set linetype 8 lc rgb "black" lw 1
set linetype 9 lc rgb "gray50" lw 1
set linetype cycle 9
There are no built-in gnuplot themes, only sets of settings which change colors.
And yes, I do use gnuplot seriously! I use it both for simple plotting and for scientific publication.
There are nice palettes available at https://github.com/Gnuplotting/gnuplot-palettes and https://github.com/aschn/gnuplot-colorbrewer
These define line styles that you can use explicitly, but with some shell escaping tricks you can make them override the default linetypes, with something like this in your .gnuplot:
palettefile(n) = sprintf("<sed 's/set style line/set linetype/' /path/to/gnuplot-gnuplot-palettes/%s.pal", n)
load palettefile("rdbu")
You can then call load palettefile(palettename) (where palettename is one of the ones available in the palette repository) whenever you want to change the default palette, so gets quite close to the theming notion mentioned above.
It looks like you are using an older version - the demos are probably made with version 5, which has a new default palette. Your colors look like version 4 or below.
The new version has a lot of new, more powerful features. The new cariolatex terminal can produce really nice publication quality plots out of the box, or with very few tweaks.
The most recent versions of gnuplot (5) have the left hand colour palette by default (at least the wxt terminal). They mention it helps readers with colour blindness.
I suggest you type in: help set colorsequence.
p.s. I also use gnuplot always for all my scientific publications.
Although the result is similar to that of andyras, here is another solution:
as the default colours depend on the terminal type, switch to the desired terminal type with set term and then type
show linetype
I've seen several examples of labels in gnuplot (where two columns define the 2D plot, and a third column is used to make labels that apply to the points in the 2D plot) but I can't seem to get them to work on my gnuplot.
We have 4.0, and it seems like the standard examples are for 4.2 and higher.
Is there any way to use three columns to define a 2d plot with labels in gnuplot 4.0?
I've tried things like:
plot "datafile.gnu" using ($3+3):($4+3):2 with labels, "datafile.gnu" using 3:4 with lines
plot "datafile.gnu" using 3:4:2 with labels, "datafile.gnu" using 3:4
plot "datafile.gnu" using 3:4 with lines, '' using 2 with labels
....
3 & 4 are columns for the x & y and 2 is the column containing the label I want at each point.
No matter what I try I'm getting errors back.
gnuplot4.0 is ancient. As such, I don't have access to a copy of it -- However, you might try something like this:
!awk '{printf "set label \"%s\" at %f,%f point\n",$3,$1,$2 }' datafile.gnu > labels.gnuplot
load "labels.gnuplot"
I would like to run animations in PostScript smoothly. To see what I want, let me switch to PostScript directly. Call ghostscript, and
200 dup scale .5 setgray 0 0 3 3 rectfill
We have now a gray square.
0 setgray 0 1 3 1 rectfill
With a black stripe in it. We will now fill that stripe, one time white
and black in succession:
{1 setgray 0 1 3 1 rectfill 0 setgray 0 1 3 1 rectfill} loop
You will see now some flickering of black and white rectangles that
are smaller than the original black stripe. Ideally, we would see
the original grey square. Or almost. Where can I get such functionality today?
To see a more interesting animation sequence searching for magic
squares of size 5:
wget http://www.complang.tuwien.ac.at/ulrich/gupu/l5.eps.gz
zcat l5.eps.gz | ghostscript -
A couple of years ago I did try to address these issues. But it never went into ghostscript or Xfree. See
this page. Maybe there are some better ideas now?
Edit: After reading the responses so far, let me clarify one issue here. Essentially, there are two independent issues in this question:
How should an animation be viewed from the language level? I believe, the best way is to view each frame as a single page. With copypage incremental changes can be realized with low effort. Sadly, that semantics of copypage is only present in Level 1 and 2. In Level 3, the meaning of copypage changed to showpage. I did - many years ago - a little modification to ghostscript to delay all visible changes up to copypage or showpage. In this manner, a single XCopyArea containing the changed area is performed locally on the server (that is, the display).
How should actual changes on the visual display be synchronized to avoid artefacts that where not present in the graphics described? The irregular flicker you see is not a privilege of PostScript, it seems to be present in any double-buffered system I have seen so far. Just try to program this in whatever system you see fit.
Further edit:
To get the right language level, that is level 1 or 2 do (for ghostscript):
systemdict /.setlanguagelevel known {2 .setlanguagelevel} if
Edit: I am adding this comment to may attract some new postscript contributors.
We explored some of these issues in this thread on comp.lang.postscript.
Since the release of the Level 2 standard, Postscript is a garbage-collected language. You can disable collection of user objects with the fragment -2 vmreclaim, but it doesn't accomplish much. You can disable ALL ghostscript garbage collection by invoking with the -dNOGC option. This should help prevent stalling and spitting with parts of the image.
Ghostscript has a non-standard operator called flushpage, which synchronizes the rendering with the execution. This helps make sure that everything is seen before it's gone.
- flushpage -
On displays, flushes any buffered output, so that it is guaranteed to
show up on the screen; on printers, has no effect
And for timing control, there doesn't seem to be a better way than simple busy-waiting.
/smallpause {
/flushpage where{pop flushpage}if
50 sleep } def
/pagepause {
/flushpage where{pop flushpage}if
1000 sleep } def
/sleep {
usertime add {
10 {
1 100000 div pop %busy
.1 sin 257 cos atan pop %busy busy
} repeat
dup usertime le {exit}if
} loop pop
} def
The where guards around flushpage allow you to send the same code to interpreters other than ghostscript (like a printer).
If you had an actual Display Postscript server, you could use the wait operator instead of busy-waiting.
Although I like (and upvoted) #luserdroog's answer, I don't believe Postscript should be used for animations on this way - I'd rather use some language that can run widgets or display elements that are designed for real time display and user interation - that is not the case of postscript or ghostscript.
I think it would be nice, though, use postscript for aimations for rendering purposes - just rendering a page after each modification on the image, and using an external program to assemble the different pages as animation frames.
Maybe even using postscript as a rendering engine, with the process in another language calling ghostscript to render each frame in realtime. A nice and easy to use multimedia framework to do that could be for example, the Python language with the Pygame module.
Here is a short example using "pure python + pygame".
#! /usr/bin/env python
# coding: utf-8
import pygame
size = 640,480 #(in pixels)
# multiplying factor so that the whole image is 5 units across
factor = size[0] / 5.0
# Inits pygame drawing window
screen = pygame.display.set_mode(size)
# Rectangle drawing function that scales drawing using the factor above
def draw_rect(color, rect):
new_rect = [int (r * factor) for r in rect]
return pygame.draw.rect(screen, color, new_rect)
def main():
draw_rect((128,128,128), (0, 0, 3, 3))
colors = ((255,255,255), (0,0,0))
color_index = 0
while True:
draw_rect(colors[color_index], (0, 1, 3, 1))
pygame.display.flip()
color_index = 1 - color_index
pygame.time.delay(50) # in miliseconds
try:
main()
finally:
pygame.quit()
To execute this, you have to have Python and Pygame (from http://pygame.org - there are ready packages on most linux systems for that)
Pygame's drawing API is much poorer than postscript - if you need more than rectangles
(like bezies, scaling, rotating and shearing the coordinate system, and so on), the way to go is to use Cairo + python + some display library (which might be pygame, GTK+ or qt) . Cairo is a 2D drawing library that inherits from the postscript way. - or, as I said above, to drive a ghostscript external process using Python, having it generating a rle compressed image file to stdout or a ramdrive, and that image read and displayed frame by frame using python + pygame.
Another option is to use HTML5's Canvas, and do everything in Javascript, viewable on a browser. HTML5's Canvas also inherits the Postscript way of drawing.