I'm using a multiplot with two boxes for two sets of data as legend. However, I came across the following problem: when using a grid, the second box is always behind the grid.
Using the following code (borrowed from another question in SE and modified):
set term pngcairo
set output "legends.png"
set multiplot
# make a box around the legend
set key box
# fix the margins, this is important to ensure alignment of the plots.
set lmargin at screen 0.15
set rmargin at screen 0.98
set tmargin at screen 0.90
set bmargin at screen 0.15
set xrange[0:2*pi]
set yrange[-1:1]
set grid
# main plot command
plot sin(x) title "sinus"
# turn everything off
unset xlabel #label off
unset ylabel
set border 0 #border off
unset xtics #tics off
unset ytics
#unset grid #grid off
set key at graph 0.5, 0.5
plot cos(x) ls 2 lw 2 title "cosinus"
The output you get is:
I would like the second box to be opaque to the grid, just like the first one. The command #unset grid doesn't do anything since there is no grid if you disable xtics and ytics.
Use opaque at the second key:
...
set key at graph 0.5, 0.5
set key opaque
....
Related
Can you tell us how to make the chart with all headings and captions fit into the fixed vertical size and the horizontal size is floating?
If I set small fixed image sizes, some axes captions disappear, and if I set large fixed image sizes, then there is an empty space on the sides.
And I want you to be able to specify the height of the image and gnuplot will determine for itself what its width must be to fit everything you need.
For example (margin - empty space, but on the right, the inscription didn't fit:
set terminal pngcairo notransparent enhanced font "Calibri, 15" fontscale 1.0 size 800, 800; set zeroaxis;
Apparently, gnuplot does not automatically provide enough space for long numbers in the colorbox.
Since you have a logarithmic scale from 0.0000001 to 0.1, you might want to consider to display your numbers in a different format, i.e. from 10^-7 to 10^-1.
Code:
### no long numbers in colorbox
reset session
set colorbox
set palette rgb 33,13,10
set xrange [-7:-1]
set cbrange [1e-7:0.1]
set logscale cb
set format cb "10^{%T}"
plot '+' u 1:1:(10**$1) w l lw 3 palette z notitle
### end of code
Result:
I want to plot a multiplot in gnuplot with two plots. One plot on top of another. The underlying data files for both plots will be constantly changing and every 5 seconds, both plots will be refreshed.
Is there a way to ensure that the xrange of the bottom plot always stays the same as the xrange of the top plot? The top plot will be auto scaled.
Gnuplot has set xrange writeback | restore for this. As example consider
set xrange [-10:10]
set multiplot layout 1,2
set yrange [] writeback
plot sin(x)
set yrange restore
replot x/2
unset multiplot
That uses the autoscale limits of the first plot for the second plot. In your case use of course set xrange [] writeback ... set xrange [] restore.
I am a bit confused about gnuplot margins. First of all I have no idea what units these things are pointing to. Are they pointing to the canvas coordinates OR are they a fraction of the canvas coordinates. Do they behave the same in gnuplot mode and multiplot mode?
My problem arises when plotting some data in multiplot mode. I am plotting to the screen (wtx terminal). Let's just say I am bungling things badly - I get plots off the canvas, or very small unreadable plots.
Without margins the first plot is flush against the top of the canvas, so naturally I want to push it down a bit.
Can someone explain how gnuplot margins work and if they behave the same in multiplot mode.
Yes, the margins behave very similar in "normal" plotting mode and in multiplot mode. Basically, the margins can have three different "modes":
Automatic, which is the default.
Setting each margin to a specific size, like set lmargin 2. The unit is character widths (or character heights for tmargin and bmargin).
Setting a specific position of a border relative to the whole canvas, like set lmargin at screen 0.1, which sets the left plot border at 10% of the total canvas width.
The only difference of the multiplot mode is, that the reference for the margins in 1. and 2. is given by the sites determined by the layout option:
set multiplot layout 2,2
This subdivides the whole canvas in four rectangles of equal size. Now, using
set lmargin 1
set rmargin 1
set tmargin 1
set bmargin 1
leaves a margin of one character width or height on each side of each subplot with respect to the smaller rectangles:
set multiplot layout 2,2
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set format ''
plot x
plot x**2
plot x**3
plot x**4
unset multiplot
set multiplot layout 2,2
set lmargin 1
set rmargin 1
set tmargin 1
set bmargin 1
set format ''
plot x
plot x**2
plot x**3
plot x**4
unset multiplot
If you want to set absolute positions of each border, this becomes more cumbersome, because you have to set four margins for each plot (the layout options doesn't have any effect in this case):
set multiplot
set lmargin at screen 0.1
set rmargin at screen 0.47
set tmargin at screen 0.97
set bmargin at screen 0.6
plot x
...
Gnuplot version 5 offers a quite flexible way to produce equal rectangles, see my answer to Removing blank gap in gnuplot multiplot
I'm trying to use multiplot to overlay a curve over a contour map, and here is my gnuplot script.
set term postscript enhanced color 'Times-Roman,24'
set output 'cimax_pmf.eps'
set encoding iso_8859_1
set nokey
set xlabel 'RC(\305)'
set xrange [0:12]
set yrange [0.2:1]
set ylabel 'c^2_{imax}'
set y2label 'PMF (kcal/mol)'
set y2range [-20:1]
set multiplot
set pm3d map interpolate 10,10
set view map
set isosamples 10 #increase resolution
set palette rgb 33,13,10 #rainbow color scheme
unset colorbox
splot[0:12][0.2:1] 'cisq_rrr_reduced.dat' u 1:2:3 notitle
unset map
plot[0:12] 'final_pmf.dat' u 1:2 w line lt 2 lw 2 notitle axis x1y2
unset multiplot
One thing to mention is that I have two vertical y axis, as suggested by "axis x1y2" in my script. The problem is that after running this script, I found that the second plot does not align with the first plot correctly. In other words, they have different sizes and their overlap seems to be problematic. It looks like the problem described in the first figure of this page
http://lowrank.net/gnuplot/plot3-e.html#5.10
But I cannot solve this problem by using the script similar to that page.
Thanks.
I am more familiar with multiple plots in or next to each other, but nevertheless two things might help you:
multiplot allows for "set size" command (see "help set size" for more info) to be used for each graph. But I guess if you say the script on the Not So FAQ page did not help, this is probably not enough.
It might therefore be useful to set margins (see "help set margin"), which can be used to align more precisely graphs in a multiplot. It also quite often fixes the problem of data ranges of different lengths that cause numerous misalignment problems.
I would suggest not to use pm3d and multiplot at all and instead use plot … with image. This way, you can do with a single plot command.
If I did not make any mistakes, just change your code to (everything before multiplot is unchanged):
[…]
set y2range [-20:1]
set palette rgb 33,13,10 #rainbow color scheme
unset colorbox
plot\
'cisq_rrr_reduced.dat' w image notitle,\
'final_pmf.dat' u 1:2 w line lt 2 lw 2 notitle axis x1y2
You can use gnuplot's feature of saving contour data to a file via set table (see documentation, and rather implicit example here). Something like:
...
set table 'contours.dat'
splot[0:12][0.2:1] 'cisq_rrr_reduced.dat' u 1:2:3 notitle
unset table
plot[0:12] 'final_pmf.dat' u 1:2 w line lt 2 lw 2 notitle axis x1y2, \
'contours.dat' using 1:2
Adjust for your case.
I use the following gnuplot script in order to plot a data file
reset
unset key
set size 1,1
set xrange [-10.1:11]
set yrange [-45:45]
set xlabel 'x'
set lmargin 6
set label 1 "~x{0.7.}" font "Helvetica, 20" at graph -0.1, graph 0.5
set xtics 2
set ytics 15
set mxtics 5
set mytics 5
plot "pss_data.dat" u 1:2 w dots lc rgb 'black'
set term postscript eps enhanced "Helvetica" 20 size 7in, 5in
set output 'plot.eps'
replot
reset
set terminal windows
quit
The exported .eps file is the following.
Well, in fact this is the corresponding .pdf file using Adobe Acrobat XI in order to make the conversion. However, the .pdf output contains not only the plot but all the unwanted black area above it! In an attempt to get rid off the white area I used the command line
epstopdf plot.eps
The output is the following
Now, the white area has been removed but the label at the y axis is also missing!
Any ideas? I want to have in a .pdf file only the plot (without the above white area) but with the label at the y axis.
Many thanks in advance.
Your bounding box may be incorrectly set. You can try using epstool on the eps you create:
epstool --bbox myeps.eps myneweps.eps
That should calculate the bounding box correctly, but give you a margin of zero. If you can't/don't want to install it, try adjusting the bounding box manually. There is a line near the top of the .eps file which looks like this:
%%BoundingBox: 50 50 554 770
The four numbers are the y offset, x offset, y max and x max of the output (in terms of margins you can think of them as top, left, bottom, right). You can try decreasing the second number (increasing the left margin) to see if that reveals your y axis label.
I would avoid the conversion all together by using one of gnuplot's pdf terminals (I like pdfcairo) and just use ylabel instead of set label 1 ... at graph.... Here's a simple script that you can modify for your purposes:
set term pdfcairo enhanced font "Helvetica,20"
set output "test.pdf"
set ylabel "~x{0.7.}" rotate by 0 #default rotation is 90
set xlabel "x"
plot sin(x)
Ultimately, what is happening with your script is that gnuplot is putting the label off of the viewable canvas. Some reason adobe still puts the label on the (converted) output, but I would assert that they are wrong in this case -- (they're essentially ignoring your bounding box). Of course, you could move/adjust the bounding box as suggested in the answer by andyras -- but I would argue that is a pretty hacky solution.