Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot - Using replot with png terminal

Tags:

gnuplot

I am trying to use replot with png terminal in Gnuplot.

If I do the following I get two plots on one graph without any problem:

plot sin(x)/x
replot sin(x)

Now if do the same for a png terminal type the resulting png file only contains the first plot.

set terminal png
set output 'file.png'
plot sin(x)/x
replot sin(x)

Am I missing something at the end to get the second plot in my png file?

like image 709
Noel Avatar asked Jun 15 '12 05:06

Noel


1 Answers

This is actually a very good question, and the behavior here is terminal dependent. Some terminals (e.g. postscript) will give you a new page for each replot. You have a couple of solutions...

First Option: You can make your plot prior to setting the terminal/output and then replot again after you set the terminal/output:

plot sin(x)/x
replot sin(x)
set terminal png
set output 'file.png
replot

This option is sometimes convenient if you want to plot the same thing in multiple terminals, but I rarely use it for anything else.

Second (better) Option: You can pack multiple plots into one command separating each with a comma.

set terminal png
set output 'file.png'
plot sin(x)/x, sin(x)

I very much prefer the second way -- when in a multiplot environment, this is the only way to put multiple graphs on the same plot. If you have very long functions to plot, you can break the line with gnuplot's line continuation (\ at the end of the line -- Nothing is allowed after the \, not even whitespace)

plot sin(x)/x with lines linecolor rgb "blue" linetype 7 lineweight 4, \
     sin(x),                                                           \
     cos(x)
like image 89
mgilson Avatar answered Sep 27 '22 19:09

mgilson