Gnuplot image on axis - gnuplot

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:

Related

Using gnuplot, how can I plot sin(x) in the x-z plane and sin(x) in the x-y plane, both at the same time?

Using gnuplot, how can I plot sin(x) in the x-z plane and sin(x) in the x-y plane, both at the same time? I'm guessing I need to use the set parametric command and the splot command, but I can't seem to work out the rest! Does anyone know how to do this? I'm trying to generate a plot which demonstrates the nature of an electromagnetic wave. Thanks.
Yes, parametric mode is a possibility. For example, splot u,0,sin(u), u,sin(u),0 will plot the two (!) parametric curves u,0,sin(u) and u,sin(u),0. The variable u is the parametric dummy variable, for a simple sine function we only need one of them, even in 3d mode.
It might look a bit nicer with the following settings, but this is of course my biased opinion, far from finished, and depends on your needs:
set terminal pngcairo
set output "emfield.png"
set yrange [-2:2]
set zrange [-2:2]
set parametric
umax = 6*pi
set urange [0:umax]
unset border
unset xtics
unset ytics
unset ztics
# Set zeroaxes
set xyplane at 0
set arrow from 0,0,0 to (umax*1.1),0,0 size screen 0.020,15,60 filled
set arrow from 0,1,0 to 0,-1,0 size screen 0.020,15,60 filled
set arrow from 0,0,-1.4 to 0,0,1.4 size screen 0.020,15,60 filled
splot u,0,sin(u) lc 6, u,sin(u),0 lc 7
The result looks like this:

gnuplot multiplot images in column

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.

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 4.6 xtics label disappear

I decided to migrate to the latest version of gnuplot from 4.4 to 4.6
I am having issue with the x label disappearing with version 4.6 but being there with version 4.4.
here is a stripped down version of my script.
set key outside
set title "MY TITLE"
set timefmt "%m/%d/%Y-%H:%M:%S"
set format x "%m/%d %H:%M"
set xdata time
set ylabel "Y LABEL"
set xlabel "Time"
set grid
set xtics rotate by 90 offset 0,-5
set terminal pngcairo size 1000,500 font ",9"
set xtics font ",8.0"
set ytics font ",8.0"
set output 'test.png'
plot '-' using 1:2 with linespoints ti "legend"
01/01/2013-00:15 186557
01/01/2013-01:15 254654
01/01/2013-04:00 180146
01/01/2013-06:15 191059
e
set key inside
I've identified the issue to this line
set xtics rotate by 90 offset 0,-5
Because my label is too long the offset makes it go away
if you remove the offset to
set xtics rotate by 90
Not the label show but in the middle of the chart.
Version 4.4 used to compress the chart to leave room for the label.
I guess my knowledge to gnuplot is limited.
Anyone has an idea?
thanks
UPDATED ANSWER, courtesy of Ethan Merritt
A better way to do this is to change the justification of the labels to being right justified (rather than the default centered).
set xtics rotate by 90 right
This correctly calculates the margin without needing to hardcode a margin size
The label placement here seems a little flaky to me. I think there might be a bug which I'll probably report. One workaround is to explicitly set the location of the "x-axis" via:
set bmargin at screen 0.2
The reason it seems flakey is because with set bmargin at screen 0.2, the xtic labels clearly extend higher than the position of the xlabel. However, if you comment that line out, all of a sudden they don't extend higher than the position of the xlabel.
Here are the plots with and without that line:
Perhaps cairo/pango cut out labels where any portion of the label extends past the visible "canvas" area?
As a side note, the plot also seems to be roughly correct if I use the postscript terminal...

gnuplot - no space between graph and png image edge

How to create a .png image in gnuplot to see no spaces between graph itself and image edges.
I use
set terminal pngcairo size 800,600 enhanced
I want exactly 800x600 image. And want all 0X axis correspond to [0..800] interval, and all 0Y correspond to [0..600] interval.
It looks like you want to set the margins to 0. Here is an example script:
set terminal pngcairo size 800,600 enhanced
set output 'output.png'
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
#unset tics
plot sin(x) # notitle
This way the plot will fill the canvas exactly. You can type help set margin in gnuplot for details. (Uncomment the comments in my example if you want a slightly cleaner plot.)

Resources