问题
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!
回答1:
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 toautoscale
etc. (Therefore you must also set fixedlmargin
andrmargin
).To plot the image itself, use the plotting style
with rgbimage
.You must fine-tune the
xtics
andxlabel
offset, as well as the marings.
The resulting image is:

来源:https://stackoverflow.com/questions/18398152/gnuplot-image-on-axis