Use multiplot to plot a contour map and a curve together - plot

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.

Related

iteration and parametric mode with t ranging according to a function - gnuplot

I'm trying to iterate in parametric mode to plot several concentric arcs of circles with the parameter t ranging according to a function. I've tried, among others,
a=sqrt(2)
plot [-pi/2:pi/2] a*cos(t), a*sin(t)
do for [i=2:10] {
a=sqrt(2)/i
set trange [-1./2*acos(-(a**2)/2.):1./2*acos(-(a**2)/2.)]
replot a*cos(t), a*sin(t)
}
what I see is a plot of 10 identical overlapped arcs. I also replaced replot with plot and only the last arc is retained.
I know "that iteration does not work for plots in parametric mode" (ref. "plot for" in the manual), but this is using a do for construct. There must be a way to do this! How?
System: gnuplot Version 5.2 patchlevel 2, windows 10.
Today I developed my own solution, which is
a(i)=sqrt(2)/30*(31-i)
s(t, i)=t*(1./2*acos(-(a(i)**2)/2.))/(pi/2)
set trange [-pi/2:pi/2]
plot [-pi/2:pi/2] for [j=1:30] a(j)*cos(s(t,j)), a(j)*sin(s(t,j)) lw 2
Notice that in the meanwhile I made a little math adjustment from a=sqrt(2)/i to a(i)=sqrt(2)/30*(31-i).
Output:
The settings used to output that picture are
set term wxt size 800,800
set grid
set size ratio -1
set parametric
set xrange [-1.6:1.6]
set yrange [-1.6:1.6]
The rationale behind this is that in this way I set trange only once, and then with a variable substitution I map [0:pi/2] to [0:s(pi/2,i)].
You can use the for loop inside your plot statement. Try this:
set term png
set out "tmp.png"
unset key
set parametric
plot for [i=2:10] (sqrt(2)/i)*cos(t), (sqrt(2)/i)*sin(t)
exit
Output:
Update: the solution above won't take care of the trange requirement of the question. For that, one possible solution is to create a series of tables with proper ranges, and then loop through the files created for the plot. Something like the following:
set term png
set out "tmp.png"
unset key
set parametric
do for [i=2:10] {
a=sqrt(2)/i
set trange [-1./2*acos(-(a**2)/2.):1./2*acos(-(a**2)/2.)]
set table 'data'.i.'.txt'
plot a*cos(t), a*sin(t)
unset table
}
plot for [i=2:10] 'data'.i.'.txt' w l
exit
Output:
Hope this solution works! With a little help from this post.
You can often avoid parametric mode by using the + special filename in conjunction with a using statement:
plot for [i=2:10] [t=-1./2*acos(-((sqrt(2)/i)**2)/2.):1./2*acos(-((sqrt(2)/i)**2)/2.)] '+' using (sqrt(2)/i)*cos(t):(sqrt(2)/i)*sin(t) notitle with lines

Fixing the xrange of one plot to another

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.

GNUPLOT how to add more space to indexes in labels

I try to put the space to the index in the letters of the labels of Gnuplot. I use the following command:
set terminal pngcairo size 500,400 enhanced font 'Verdana,10'
set output 'test.png'
set xlabel 'atan(~{/Symbol w}{.6\~}_2)'
set ylabel 'atan(~{/Symbol w}{.6\~}_2)'
plot sin(x)
As you can see from the plot here the _2 over-plot the symbol. Could someone help me to understand how to put extra space to the indexes?
Admittedly, this is a bit of a hacky solution but it seems to work:
set xlabel 'atan(~{/Symbol w}{.6\~} _2)'
set ylabel 'atan(~{/Symbol w}{.6\~} _2)'
Adding the space after the symbol means that the subscript 2 doesn't overlap with it:

How can I represent accurately an adjacency matrix of a big graph on a small image with gnuplot?

I am trying to create an adjacency matrix of a graph with gnuplot. The input graph has much more nodes than the pixels of the image that I will create. So, even for very sparse graphs I get very dark images.
My script is the following:
set terminal png size 800,800
set output "output.png"
set xrange []
set yrange [] reverse
set format y ""
set format x ""
unset xtics
unset x2tics
unset ytics
unset y2tics
plot 'data.dat' using 2:1 with dots lc rgb "#000000" notitle
I have thought of using 'every' to take a sample of the graph but I am not sure how I can choose an appropriate step. Using nodes/pixels for step creates a graph sparser than what I expected. Another idea is to use a heat map with colors making up for the shortage of pixels. However, I am not aware of how to create a heat map with gnuplot, since all the examples I find online seem to use a matrix for input while I use points for plotting.
Can someone provide me with an example for a heat map with points instead of a matrix as input or justify which step would be appropriate for use in order to get a good representation?

Missing label when converting eps to pdf

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.

Resources