gnuplot study notes (multiplot output to file)
Please indicate the source for reprinting: http://blog.csdn.net/liyuanbhu/article/details/78242352
Someone asked this question on Mizuki a few days ago:
Using multiplot to draw multiple pictures can be displayed on the desktop, but it cannot be output as pictures. Has anyone done it? Thank you!
In fact, this is a very small problem, and everyone is capable of solving it. It is written here mainly because I am afraid that some people will regard this as a bug of gnuplot (there are indeed many people who will easily follow the conclusion of a bug without making any effort when they encounter software problems).
The following demo uses gnuplot 5.2. In fact all the code should run fine on gnuplot 4.0 and above.
set size 1, 1
set multiplot layout 2, 2
set size 0.5, 0.5
set origin 0, 0
plot sin(x)
set origin 0, 0.5
plot cos(x)
set origin 0.5, 0
plot x**2
set origin 0.5, 0.5
plot x**3
unset multiplot
For such a test code, the output window looks like this:
Usually, we do this when we want to output an image to a file:
set size 1, 1
set multiplot layout 2, 2
set size 0.5, 0.5
set origin 0, 0
plot sin(x)
set origin 0, 0.5
plot cos(x)
set origin 0.5, 0
plot x**2
set origin 0.5, 0.5
plot x**3
unset multiplot
set term push
set term png
set output "fig2.png"
replot
set output
set term pop
Everyone pay attention to the last few lines, set term, output and replot it.
The output after this can be set is:
That is, only the last image is output.
The correct way should be like this:
set term push
set term png
set output "fig3.png"
set size 1, 1
set multiplot layout 2, 2
set size 0.5, 0.5
set origin 0, 0
plot sin(x)
set origin 0, 0.5
plot cos(x)
set origin 0.5, 0
plot x**2
set origin 0.5, 0.5
plot x**3
unset multiplot
set output
set term pop
The image output like this is:
So far, this little problem is solved.