gnuplot multiplot images in column - gnuplot

I'm trying to use multiplot to stack two image plots on top of one another, in a column. When I try to test this with x11 terminal, the images are produced separately, only one visible at a time. When I use the epslatex terminal, which is what I want, then the text is drawn correctly within the LaTeX document, but the EPS portion of the plot is produced as two separate pages, resulting in a figure that is missing a lower half.
Here's the multiplot section of my script:
set multiplot 2,1
set cbrange [-0.4:0.4]
set cbtics -0.4,0.2,0.4
unset xlabel
set tmargin at screen 0.95
set bmargin at screen 0.60
plot data u 1:2:3 with image notitle
set cbrange [-0.1:0.1]
set cbtics -0.1,0.05,0.1
set xlabel "$x$"
set tmargin at screen 0.50
set bmargin at screen 0.15
plot data u 1:2:3 with image notitle
unset multiplot
unset output
What results in the document is this:
I have tried enlarging the vertical size of the plotting area(per this question), but what this does is increase size of each page in the EPS file. To be clear, the product of plotting with epslatex is an EPS file containing two pages, the first with the first plot at the position that I want (near the top), and the second with the second plot at the position that I want (near the bottom).

This normally happens when you are not in multiplot mode. For me, set multiplot 2,1 gives an error message "only valid in the context of an auto-layout command". The command set multiplot layout 2,1 works with Gnuplot 5.0 and 4.6.
As a side note: This behavior can be used to produce animated gifs with set terminal gif animate, each plot command creates a new frame.

Related

gnuplot multiplot layout not being overridden by set origin, ways to position subplots

This question is to some part identical to what has already been asked here. But the referenced question never received the answer to the point whether the issue presented here is a bug or documentation confusion.
Documentation states with respect to the layout option of multiplot:
With the layout option you can generate simple multiplots without
having to give the set size and set origin commands before each plot:
Those are generated automatically, but can be overridden at any time.
My understanding of that text is that layout sets origin and size and at any time, i can change those specifications. Then this should work:
set xrange [0:10]
set multiplot layout 3,1 margins 0.1,0.95,0.12,0.95 spacing 0,0
unset key
plot cos(x) axes x1y1 w l ls 3 notitle
plot sin(x) axes x1y1 w l ls 3 notitle
set key bottom center out horizontal
plot sin(x) axes x1y1 w l ls 3 notitle
set origin 0.3,0.5
set size 0.2,0.1
set xrange [1:2]
plot cos(x) axes x1y1 w l ls 3 notitle
unset multiplot
But it does not. gnuplot completely ignores set size and set origin commands. What it should do is to plot 3 plots under each other and then create an inset at screen position (0.3,0.5) of size relative to canvas (0.2,0.1).
My questions are:
Is this a bug that should be reported or is this poorly formulated documentation issue (that layout can be overridden by set position and set size)?
multiplot offers two ways to position the sub-plots, set origin + set size and set *margin where * stands for one of b,t,l,r. Can someone provide a deeper explanation when one should use which? (For me it feels the proper way that was meant to do it is set origin and margins just became a dirty trick that works but was not meant for that)
What would be the cleanest way to produce the plot that I am looking for that would be easily reproducible (for any other problem, not just 3 plots but any plots and without some tedious calculations of positions)?
Is there a way to print the settings of origin, size, margins and any other relevant settings that are automatically calculated (and used) when the layout option is specified?
My guess would be that it is a bit unclear documentation.
It's a matter of taste and convenience and depends on your situation. Setting origin and size is setting the place for the (sub-)"canvas". This (sub-)"canvas" still can have some individual b,t,l,r margins. Note, margins are the space between graph border and canvas-border.
Apparently, the margins which you are setting in the multiplot layout are kept for your extra plot.
So, apparently you have to reset them, e.g. set margins 0,0,0,0. And then you are probably getting your intended plot.
I am not aware that you can extract the automatically calculated values for margins. There are no such values
listed in show var GPVAL.
Code:
### multiplot layout with manual origin and size
reset session
set xrange [0:10]
unset key
set ytics 0.5
set multiplot layout 3,1 margins 0.1,0.95,0.12,0.95 spacing 0,0
plot cos(x) axes x1y1 w l ls 3 notitle
plot sin(x) axes x1y1 w l ls 3 notitle
set key bottom center out horizontal
plot sin(x) axes x1y1 w l ls 3 notitle
set margins 0,0,0,0
set origin 0.3,0.5
set size 0.2,0.1
set xrange [1:2]
plot cos(x) axes x1y1 w l ls 3 notitle
unset multiplot
### end of code
Result:

How to put two plots with inset side by side in gnuplot?

I am trying to create two plots in Gnuplot side by side using multiplot. The problem is that how can I add inset to each one.
I wanted to point your attention to the gnuplot demo page (gnuplot demo page), however, I couldn't find an example of such insets in multiplots right away.
Simply use set multiplot layout 1,2 and continue plotting but with different sizes and offsets. See example below:
Code:
### multiplot with insets
reset session
set multiplot layout 1,2
plot x**2
plot x**3
set size 0.3,0.3
set origin 0.1,0.6
set ytics 0.5
plot sin(x)
set size 0.3,0.3
set origin 0.6,0.6
plot cos(x)
unset multiplot
### end of code
Result:

Is there a bug in Gnuplot 5.2 (patch 5) with `multiplot` command?

I'm running Gnuplot version 5.2, patch level 5, and I am getting unexpected behavior from the multiplot command. In efforts to produce two plots, one smaller and superimposed on the larger one, I am using the multiplot environment in the following way:
reset
set multiplot
set origin 0,0
set size 1,1
plot "first_file.dat"
set origin 5,5
set size 0.5,0.5
plot "second_file.dat"
unset multiplot
When I first run set multiplot an empty canvas shows up that I close. Then, when I enter unset multiplot nothing happens. From following instructions online it seems like the unset command is supposed to produce the plot, but it doesn't. Am I doing something wrong, or is there a potential bug with this version?
Why do you close the empty canvas? You won't see anything until you plot your data. The following code gives two superimposed plots. However, the set origin coordinates are relative to the screen (ranging from 0.0,0.0 to 1.0,1.0). If you want to place the second graph relative to some coordinates of the first graph, this probably would require some calculations.
reset session
set colorsequence classic
set multiplot # will show an emtpy canvas
plot sin(x) lt 1 # will show the first plot
set origin 0.1, 0.45 # origin coordinates are relative to the screen
# not to the coordinates of the first plot
set size 0.5,0.5
plot cos(x) lt 2 # will show the second plot on top of the first plot
unset multiplot
Result (wxt terminal):

Gnuplot cblabel not appearing

I am trying to plot a function of two variables represented in tabular form. I would like to label my color bar while representing this as a heatmap. No matter how much I rescale, no luck, and I don't even see the colorbar label appearing. Here is my gnuplot script:
set title "Flux in core vs radius and height"
set view map
set cblabel "Neutron flux (cm^-2 s^-1)"
set xlabel "Radius (cm)"
set ylabel "Axial distance from center (cm)"
splot "flux.out" using 1:2:3 with image
And the result looks like this, lacking a colorbar label:
The cblabel is printed outside the picture. You can manually adjust the margins to make some space for the label:
set lmargin at screen 0.1
set rmargin at screen 0.7
I used at screen because else the picture would be cropped again. And I also set lmargin because else in my test the ylabel would not fit on the page.
Tested with Gnuplot 4.6.

Gnuplot image on axis

I'm trying to model a certain progress through some environment. The x axis would represent the location (based on x coordinate) in the environment.
In order to make this clear, I'd like an image of the environment (based on a .png) on the x axis (the environment is rather wide and not that high, so it should look good) of my plot, basically as an xtics/x-axis label.
Do you have any suggestions on how to approach this?
Thanks in advance!
You can either plot both the image and the data in one plot command, or with multiplot. The first variant is easier, but the image is inside the plot, the other is a bit more complicated, but allows arbitrary positioning of the "axis image".
The dummy image "gradient.png" for the axis is
One plot command:
set yrange[0:1]
set xrange[0:1]
plot 'gradient.png' binary filetype=png dx=0.0015 dy=0.002 with rgbimage t '',\
x**2
The result is:
Using multiplot
set yrange[0:1]
set xrange[0:1]
set lmargin at screen 0.1
set rmargin at screen 0.98
set tmargin at screen 0.98
set bmargin at screen 0.2
set xtics offset 0,-1.5
set xlabel 'xlabel' offset 0,-1.5
set ylabel 'ylabel'
set multiplot
plot x**2
set tmargin at screen 0.2
set bmargin at screen 0.15
unset border
unset tics
unset xlabel
unset ylabel
unset key
set autoscale xy
plot 'gradient.png' binary filetype=png with rgbimage
unset multiplot
As you can see, this requires a bit more effort. To explain the details:
You must set explicit margins so that the axis image can be placed exactly below the main plot.
Before plotting the axis image, you must remove tics, labels, reset ranges to autoscale etc. (Therefore you must also set fixed lmargin and rmargin).
To plot the image itself, use the plotting style with rgbimage.
You must fine-tune the xtics and xlabel offset, as well as the marings.
The resulting image is:

Resources