GNUplot - How to have an image as a key? - gnuplot

I understand that we can omit the key in GNUplot using unset key. If I want to insert a small image to signify the key onto a XY 2-D plot, how to do it? In MS-Excel, it is just a matter of copying an image and pasting it on to the plot and adjusting its placement and size. Can such a thing be done in GNUPlot too? By what plot option? I am attaching a sample a of what I expect in a multiplot I made (the plot on the top left). And I have the small molecule image as a png file. I have also listed the code below. Please help me. Thanks.
reset
set size 1,1
set multiplot
unset key
#CPD
set size 0.5,0.5
set origin 0,0.5
unset title
plot 'Practice1.dat' using 1:2 w points lw 3 lc rgb 'red'
plot 'Practice1.dat' using 1:6 smooth csplines lw 3 lc rgb 'red'
#Ethene
set size 0.5,0.5
set origin 0.5,0.5
set title 'Ethene'
plot 'Practice1.dat' using 1:3 w l lw 3 lc rgb 'blue'
#Benzene
set size 0.5,0.5
set origin 0,0
set title 'Benzene'
plot 'Practice1.dat' using 1:4 smooth csplines lw 3 lc rgb 'green'
#H2
set size 0.5,0.5
set origin 0.5,0
set title 'H2'
plot 'Practice1.dat' using 1:5 w l lw 3 lc rgb 'black'

The image will be a plot in itself.
plot "image.png" binary filetype=png center=(975,40) dx=200 w rgbimage, \
'Practice1.dat' using 1:2 w points lw 3 lc rgb 'red', \
'Practice1.dat' using 1:6 smooth csplines lw 3 lc rgb 'red'
Note that you should avoid having several plot commands without changing origin/size in multiplot, as the labels and borders are overlaid and this may change their appearance depending on terminal (because e.g of antialiasing), hence the usage of , and the splitting of the command on multiple lines (with \)
Note also that set multiplot could have done the layout of your simple 2x2 plot all by itself for you, set multiplot layout 2,2

Related

How can I keep previous plot in gnuplot

Need to mark with circle on graph, but it doesn't overlap
#set multiplot layout 2, 1 # engage multiplot mode
#set multiplot
set font "arial,12"
set autoscale
set datafile separator comma
#set offset 0,0,.5,.5
#set autoscale fix
set xtics out nomirror
set ytics out nomirror
unset border
set border 3
set format y "%0.04s %cV "
set format x
#set object circle at 5.2055,3430 size 25.5 lw 5 fc rgb "red"
$data <<EOD
3400,5.2055
EOD
plot [3200:4400] "shurb/foo.csv" u 1:2 w l lc rgb 'dark-green' title 'AP',\
$data using 1:2 with circle lw 1 lc rgb 'red' notitle' ,
#unset multiplot
#set output
It is only drawing second one or first one, so I have to merge them on same plot.
How can I mark with circle or merge these two plots? Why I couldn't overlap them.
Maybe I cannot fully follow what you are trying to do. How do you get two plot with a single plot command?
There is no need to use multiplot. Simply plot your datafile and your datablock $data with a single datapoint.
By the way, your commented #set object circle at 5.2055,3430 size 25.5 lw 5 fc rgb "red" has swapped x-, and y-coordinates. So, this circle object would not be visible on your plot.
Script: (works with gnuplot>=5.2.2)
### plot with circles
reset session
# create some test data
set table $Test separator comma
plot [3200:4400] '+' u 1:(sin($0/6)*cos($0/20)/2.8*0.005+5.205) w table
unset table
$data <<EOD
3400, 5.2055
EOD
set datafile separator comma
set format y "%.4f mV"
set key noautotitle
plot [3200:4400] $Test u 1:2 w l lc "dark-green", \
$data u 1:2 w circle lw 1 lc "red"
### end of script
Result:

Plotting boxerrorbars and linespoints on the same graphic

I'm trying to plot two different sets of data on the same graph using gnuplot. The first set must be plotted as boxerrorbars, and the second one as linespoints. But, when I run the code bellow on gnuplot I get the following error:
"/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.gnu", line 20: warning: Skipping data file with no valid points
plot '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars fc rgb 'forest-green' title 'EnergyPKG [W]' axes x1y1, '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dsz.dat' u 1:2 w linespoints t 'Data Size bytes' axes x1y2
^
"/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.gnu", line 20: all points y2 value undefined!
The code:
set terminal pngcairo enhanced font 'arial,10' fontscale 1.5 size 1024, 768
set output '/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.png'
unset border
set grid
set style fill solid 0.25 noborder
set boxwidth 0.5 absolute
set title 'Ranking 1 '
set xlabel 'Query.Job'
set ylabel 'EnergyPKG [W]'
set style histogram errorbars gap 2 lw 1
set style data histograms
set xrange [-0.5:3]
set yrange [0:]
set key under autotitle nobox
set ytics nomirror
set y2tics nomirror
set y2range [0:]
set y2label 'Data Size [bytes]'
plot '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars fc rgb 'forest-green' title 'EnergyPKG [W]' axes x1y1, \
'//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dsz.dat' u 1:2 w linespoints t 'Data Size bytes' axes x1y2
ranking.1.EnergyPKG.dat:
q22.2 23.0008220833333 0.237935519166793
q16.2 22.988090297619 1.18050606267611
q07.4 10.6937465361916 0
ranking.1.EnergyPKG.dsz.dat:
q22.2 23359824
q16.2 1987871
q07.4 38
I can't figure out where the problem really is.
The values in the first column aren't valid numerical values, you must use the zeroth column also when plotting the linespoints (as you already do for the boxes):
dir ='/home/flav/salaak/src/www/plots/'
plot dir.'ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars axes x1y1,\
dir.'ranking.1.EnergyPKG.dsz.dat' u 0:2 w lp axes x1y2
And, please restrict the script you post to a bare minimum, which however still shows the problem. All those ranges, labels, tic settings etc are superfluous and make it more difficult to identify the problem.

How can I plot two surfaces that intersect each other

I've been trying to make 3d plots of surfaces from datasets using gnuplot. I have been partially successful using the following code:
set view 65,45
unset colorbox
set lmargin 14
set pm3d depthorder nohidden3d
set ylabel "angles [deg]"
set zlabel offset -2,0 "energy [eV]"
set palette defined (0 'blue', 1 "blue", 3 "blue", 4 'red')
splot "S1.dat" u 1:2:3:4 w pm3d ti "S1", "T2.dat" u 1:2:3:4 w pm3d ti "T2"
which results in the following image:
image1
The problem is, the border region (the "seam") between the two surfaces is not clearly visible because the tiles are colored with one color only. To make things clearer, here's what I obtain without pm3d (with or without hidden3d):
set terminal png size 800,800
set output "testimg2.png"
set view 65,45
unset colorbox
set lmargin 14
set isosamples 19,44
set hidden3d
set ylabel "angles [deg]"
set zlabel offset -2,0 "energy [eV]"
set palette defined (0 'blue', 1 "blue", 3 "blue", 4 'red')
#splot "S1.dat" u 1:2:3:4 w pm3d ti "S1", "T2.dat" u 1:2:3:4 w pm3d ti "T2"
splot "S1.dat" u 1:2:3 w l lc rgb "blue" ti "S1", "T2.dat" u 1:2:3 w l lc rgb "red" ti "T2"
unset hidden3d
set output "testimg3.png"
splot "S1.dat" u 1:2:3 w l lc rgb "blue" ti "S1", "T2.dat" u 1:2:3 w l lc rgb "red" ti "T2"
image 2 (hidden3d)
image 3 (no hidden3d)
So essentially what I want is a picture like my second image, where you can clearly see the border between the surfaces, but with filled tiles.
The closest I've seen to this is fig 3 in the following page:
http://www.gnuplotting.org/klein-bottle/
where you can see where the bottle meets the handle.
Can anyone help? If this is not possible with gnuplot, can anyone suggest an alternative?
to plot 2 planes in 3d, enter functions for z, comma separated, e.g.
plane 1: 4x+2y+2z = 12
plane 2: -3x-2y+8z = 12
gnuplot> splot (-4*x-2*y+12)/2, (3*x+2*y+12)/8
plot of 2 planes

Stacked and grouped bar histogram with Gnuplot

I would like to reproduce a bar chart like this one, i.e.: multiple groups, every group has many bars (4 bars in my case), each bar is segmented in a few slices (two slices in my case).
In my case, I have four algorithms applied on vectors of different sizes (2^0 to 2^20). Each algorithm has two "sections", local computation and communication. For each vector size I want to show the time required by each algorithm to perform the local computation and the communication, along with the total time corresponding to the sum of these two sections.
As a result, I would like to have a group for every vector size. In each group there are four bars corresponding to the four algorithms and each bar is segmented in a (e.g.) red part corresponding to the local computation and a blue part corresponding to the communication.
Is this feasible with gnuplot? I can provide data in whatever format is useful.
Many thanks in advance.
For your data set it doesn't make sense to stack the local and comm parts, because the comm part is to small to see it in the graph. In any case it would also be quite tricky to combine stacked and clustered, depending on the further requirements (legend entries, tick labels etc).
Here is an example of how to plot a clustered histogram for your data set:
set style histogram clustered gap 1
set style data histogram
set style fill solid 1.0 noborder
set termoption enhanced
set xtics out nomirror
myxtic(x) = sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5)))
plot 'test.dat' using ($2+$3):xtic(myxtic(stringcolumn(1))) title 'Algorithm 1',\
for [i=2:4] '' using (column(2*i)+column(2*i+1)) title sprintf('Algorithm %d', i)
The result is:
To group by algorithm, you can create new groups with the newhistogram keyword:
set style histogram rowstacked title offset 4,1
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set xtics rotate by 90 right
plot newhistogram "Algorithm 1" lt 1,\
'test.dat' using 2:xtic(1) title columnheader, \
'' using 3 title columnheader,\
newhistogram "Algorithm 2" lt 1,\
'test.dat' using 4:xtic(1) notitle, \
'' using 5 notitle,\
newhistogram "Algorithm 3" lt 1,\
'test.dat' using 6:xtic(1) notitle, \
'' using 7 notitle,\
newhistogram "Algorithm 4" lt 1,\
'test.dat' using 8:xtic(1) notitle, \
'' using 9 notitle
The local and comm dat are stacked, but the comm part is so small, that you cannot see it in the graph (only when you zoom in).
For the output I used 4.6.3 and the following settings:
set terminal pngcairo size 1000,400
set output 'test.png'
set xtics font ',6'
The result is:
A bit more sophisticated display of the xtics requires some tricking, because for histograms the xtics aren't treated as being numerical, but rather strings. Here is an example:
set terminal pngcairo size 1000,400
set output 'test.png'
set style histogram rowstacked title offset 0,-0.5
set bmargin 3
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set termoption enhanced
set xtics out nomirror
myxtic(x) = (int(floor(log(x)/log(2) + 0.5)) % 5 == 0) ? sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5))) : ""
plot newhistogram "Algorithm 1" lt 1,\
'test.dat' using 2:xtic(myxtic(real(stringcolumn(1)))) title columnheader, \
'' using 3 title columnheader,\
newhistogram "Algorithm 2" lt 1,\
'test.dat' using 4:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 5 notitle,\
newhistogram "Algorithm 3" lt 1,\
'test.dat' using 6:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 7 notitle,\
newhistogram "Algorithm 4" lt 1,\
'test.dat' using 8:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 9 notitle
With the result

Multiple colorbars in gnuplot

I'm trying to plot two data series in the same graph with multiplot. I would like each of the two data series to be plotted with a different palette. So far I've been trying with multiplot,
set multiplot layout 1,1
#
set palette rgb 21,22,23
splot "S1" using ($1):($2):($3):($5) with points pt 7 ps 3 palette notitle, \
"S1" using ($1):($2):($3):($5) with impulses linecolor "black" notitle
#
set palette rgb 23,28,3
splot "S1" using ($1):($2):($3):($5) with points pt 7 ps 3 palette notitle, \
"S2" using ($1):($2):($3):($5) with impulses linecolor "black" notitle
#
unset multiplot
however, I can not visualize in the X11 terminal the two series at the same time.
Any idea?

Resources