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
Related
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:
I am using Windows 10 and Gnuplot 5.0.
I have a script to plot several graphs simultaneously:
GNUTERM = "wxt"
set terminal wxt
set termoption enhanced
set encoding iso_8859_1
set multiplot layout 1,3
set xtics out
set ytics out
set xtics nomirror
set ytics nomirror
set xzeroaxis linetype 2 linewidth 1.5
show xzeroaxis
# Graph1
set key center right
set xrange [3.3:9.0]
set yrange [-0.1:1.10]
set title "Title 1"
set xlabel "x"
set ylabel "y"
plot \
"results_1.dat" u 1:2:4 title "exp." with e pointtype 9 pointsize 0.5 linecolor rgb "red" , \
"results_1.dat" u 1:3 title "fit." with line linecolor rgb "black" linewidth 2 dashtype 2 smooth bezier
# Graph2
set xrange [3.3:9.0]
set yrange [-0.1:1.10]
set key top right
set title "Title 2"
set xlabel "x"
set ylabel "y"
plot \
"results_2.dat" u 1:2:4 title "exp." with e pointtype 9 pointsize 0.5 linecolor rgb "blue", \
"results_2.dat" u 1:3 title "fit." with line linecolor rgb "black" linewidth 2 dashtype 2 smooth bezier
# Graph3
set xrange [3.3:9.0]
set yrange [-0.1:1.10]
set key outside vertical top right
set title "Title 3"
set xlabel "x"
set ylabel "y
plot \
"results_3.dat" u 1:2:4 title "exp." with e pointtype 9 linecolor rgb "red", \
"results_3.dat" u 1:3 title "fit." with line linecolor rgb "black" linewidth 2 dashtype 2 smooth bezier
unset multiplot
pause 3
reread
However, instead of getting the legend outside only for the graph 3, all legends are shown outside the graphs (see attached image)
I want legends 1 and 2 inside the graphs and legend 3 outside. What's wrong in my script?
Any help is appreciated.
Supernono06
It's hard to say without being able to run your script, but if I had to guess I'd say that you request the legend to be outside for graph 3, and when you reread the script you don't put it back inside. Try something like
set key inside center top
for the first graph (or add a reset statement to the beginning of your script).
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
This question already has answers here:
Place key below multiplot graph in gnuplot
(2 answers)
Closed 8 years ago.
I want to put this two graphs together and I would like to use only one key. If I set one with notitle I could get them with only key, however the shape of the graphs will change.
set term postscript eps
set output "temp.eps"
set multiplot layout 1,2
set xtics ("32" 0, "128" 2, "512" 4, "2048" 6, "8192" 8)
#set grid ytics
set xrange [0:8]
set yrange [0:100]
p "8" u ($0):($6) w lp ps 0.75 notitle, "10" u ($0):($6) w lp lc rgb "#228B22" ps 0.75 notitle, "12" u ($0):($6)w lp lc rgb "black" ps 0.75 notitle , "14" u ($0):($6)w lp lc rgb "blue" ps 0.75 notitle, "16" u ($0):($6) w lp lc rgb "#D2691E" ps 0.75 notitle, "18" u ($0):($6)w lp lc rgb "#8A2BE2" ps 0.75 notitle, "20" u ($0):($6) w lp lc rgb "#20B2AA" ps 0.75 notitle
set xtics ("32" 0, "128" 2, "512" 4, "2048" 6, "8192" 8)
#set grid ytics
set xrange [0:8]
set yrange [0:100]
set xlabel "nel"
#set key location
set key invert
set key reverse
set key center right
set key outside
p "8" u ($0):($6) w lp ps 0.75 title "8", "10" u ($0):($6) w lp lc rgb "#228B22" ps 0.75 title "10", "12" u ($0):($6)w lp lc rgb "black" ps 0.75 title "12", "14" u ($0):($6)w lp lc rgb "blue" ps 0.75 title "14", "16" u ($0):($6) w lp lc rgb "#D2691E" ps 0.75 title "16", "18" u ($0):($6)w lp lc rgb "#8A2BE2" ps 0.75 title "18", "20" u ($0):($6) w lp lc rgb "#20B2AA" ps 0.75 title "20"
unset multiplot
This would produce something like:
As it can be seen, the shape of one graph would change due to the legend on its right. I looking for a way of using only legend and both figures using the shape of the graph on the left.
This question has two parts which I will address separately.
1) Can I use the same key for multiple plots?
No, unless the key would happen to be the same for the data in both plots anyway. For example, two plots with two lines each where the two lines would have the titles 'one' and 'two' in both plots could share the same key; two plots with one line each with the titles 'one' and 'two' in the separate plots could not share the same key.
2) How do I get my multiplots to be the same size when I have a key?
There is no easy way to do this, either you manually adjust the sizes of the plots, or you set up functions like in this answer.
In your case, it could look something like:
#!/usr/bin/env gnuplot
### n: change this parameter to equal the number of data sets to be plotted
n = 2
# l: left margin in pixels
l = 75.0
# k: key height in pixels (right margin)
k = 150.0
# m: margin between plots
m = 40.0
# p: plot width
p = 300.0
# w: width of output in pixels
w = p*n + m*(n-1) + l + k
### functions to help set top/bottom margins
lft(i,n,w,l,k) = (l+(w-l-k)*(i-1)/n)/w
rgt(i,n,w,l,k) = (l+(w-l-k)*i/n - m)/w
### first set up some basic plot parameters
set term pngcairo enhanced size w,600
set output 'multikey.png'
set ylabel 'Y Axis'
set xlabel 'X Axis'
set multiplot layout 1,(n+1) title 'Main title'
### First plot
# change only plot command here
currentplot = 1
set lmargin at screen lft(currentplot,n,w,l,k)
set rmargin at screen rgt(currentplot,n,w,l,k)
unset key
plot sin(1*x) notitle, \
sin(2*x) notitle
unset ylabel
### Middle data plot (commented out for this example)
# copy and paste this code to make more middle plots
#currentplot = currentplot + 1
#set lmargin at screen lft(currentplot,n,w,l,k)
#set rmargin at screen rgt(currentplot,n,w,l,k)
#unset title
#replot
### Last data plot
# change only plot command here
currentplot = currentplot + 1
set lmargin at screen lft(currentplot,n,w,l,k)
set rmargin at screen rgt(currentplot,n,w,l,k)
set xtics
replot
### Key plot
set lmargin at screen rgt(n,n,w,l,k)
set rmargin at screen 1
set key center center
set border 0
unset tics
unset xlabel
unset ylabel
set yrange [0:1]
plot 2 t 'Line 1', \
2 t 'Line 2'
unset multiplot
The result looks like this:
Note that I just provided example code. You might need to change it to get a proper plot.
You can set the size of the individual plots in multiplot using the following example: (It is an example , you might have to work with to get a correct size for your plots.)
set size 0.8,1.2
Try setting it for each of the individual plots.
You can set the overall size by
set terminal postscript enhanced eps 24 color size 10cm,15cm
I have a very simple dataset:
Critical 2
High 18
Medium 5
Low 14
Creating a bar chart in gnuplot out of this dataset is easy, but all the bars are the same colour. I want to have it so that Critical is black, high is red, etc, but there seem to be hardly any online tutorials for doing this.
Can anyone point me in the right direction?
set xrange [-.5:3.5]
set yrange [0:]
set style fill solid
plot "<sed 'G;G' test.dat" i 0 u (column(-2)):2:xtic(1) w boxes ti "Critical" lc rgb "black",\
"<sed 'G;G' test.dat" i 1 u (column(-2)):2:xtic(1) w boxes ti "High" lc rgb "red" ,\
"<sed 'G;G' test.dat" i 2 u (column(-2)):2:xtic(1) w boxes ti "Medium" lc rgb "green",\
"<sed 'G;G' test.dat" i 3 u (column(-2)):2:xtic(1) w boxes ti "Low" lc rgb "blue"
This takes sed and triple spaces your file so that gnuplot sees each line as a different dataset (or "index"). You can plot each index separately using index <number> or i <number> for short as I have done. Also, the index number is available as column(-2) which is how we get the boxes properly spaced.
Possibly a slightly more clean (gnuplot only) solution is using filters:
set xrange [-.5:3.5]
set yrange [0:]
set style fill solid
CRITROW(x,y)=(x eq "Critical") ? y:1/0
HIGHROW(x,y)=(x eq "High") ? y:1/0
MIDROW(x,y) =(x eq "Medium") ? y:1/0
LOWROW(x,y) =(x eq "Low") ? y:1/0
plot 'test.dat' u ($0):(CRITROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "black" ti "Critical" ,\
'' u ($0):(HIGHROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "red" ti "High" ,\
'' u ($0):(MIDROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "green" ti "Medium" ,\
'' u ($0):(LOWROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "blue" ti "Low"
This solution also doesn't depend on any particular ordering in your datafile (which is why I prefer it slightly to the other solution. We accomplish the spacing here with column(0) (or $0) which is the record number in the dataset (in this case, the line number).
Here is how you can do this using the linecolor variable option.
If you know, that the lines are always in the same, known order, you can use the row number (zeroth column, $0) as linetype index:
set style fill solid noborder
set linetype 1 lc rgb 'black'
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'
set yrange [0:*]
unset key
plot 'alerts.txt' using 0:2:($0+1):xtic(1) with boxes linecolor variable
If the order may vary, you can use a gnuplot-style indexing function, which determines the index of the warning level from a string with space-separated words:
alerts = 'Critical High Medium Low'
index(s) = words(substr(alerts, 0, strstrt(alerts, s)-1)) + 1
set style fill solid noborder
set linetype 1 lc rgb 'black'
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'
set yrange [0:*]
unset key
plot 'alerts.txt' using 0:2:(index(strcol(1))):xtic(1) with boxes linecolor variable