How to use Gnuplot to print 3D plots (splot) with error bars and different linespoints - gnuplot

using Gnuplot to plot 3D charts with splot and errors with zerror does not allow us to have different lines with points. Here are examples. I would like to use splot with error bars and still differentiate lines by different points. Like it is mentioned here:
The operation of with is also the same as in plot, except that the
plotting styles available to splot are limited to lines, points,
linespoints, dots, and impulses; the error-bar capabilities of plot
are not available for splot.
Is there another solution for this problem in Gnuplot?

As you note, there doesn't seem to be a direct plotting style for drawing error bars in 3D. It is possible to manipulate the input data to pseudo-draw the error bars with lines style.
Sample Script:
$inputdata <<EOD
# x y z zlow zhigh
1 1 1 0 2
2 1 2 1 3
3 1 3 2 4
4 1 4 3 5
5 1 5 4 6
1 2 5 1 7
2 2 4 1 7
3 2 3 1 7
4 2 2 1 7
5 2 1 1 7
1 3 3 1 4
2 3 3 2 5
3 3 3 3 6
4 3 3 2 5
5 3 3 1 4
EOD
# construct errorbar's line segments data
set table $first
plot $inputdata using 1:2:4:($1-0.1):4:5:0 with table
set table $second
plot $inputdata using 1:2:5:($1+0.1):4:5:0 with table
unset table
# summarize data into data block $errbars
stats $inputdata using 0 nooutput
set print $errbars
do for [i=1:STATS_records] {
print $first[i]
print $second[i]
print ""
print ""
}
set print
set xrange [0:6]
set yrange [0:4]
set key noautotitle
splot $inputdata using 1:2:3:2 with linespoints pt 7 lc variable, \
$errbars using 1:2:3:2 with lines lc variable, \
$errbars using 4:2:5:2 with lines lc variable, \
$errbars using 4:2:6:2 with lines lc variable
pause -1
It uses the line-wise data (x,y,z,zlow,zhigh) of the data points and error range as inputs to build the data to draw the error bars and whiskers. Once that's done, we can draw each part of the error bar in lines style.
Result:
Here's another solution using vector style which is actually much simpler than above script.
Sample script:
$inputdata <<EOD
# x y z zlow zhigh
1 1 1 0 2
2 1 2 1 3
3 1 3 2 4
4 1 4 3 5
5 1 5 4 6
1 2 5 1 7
2 2 4 1 7
3 2 3 1 7
4 2 2 1 7
5 2 1 1 7
1 3 3 1 4
2 3 3 2 5
3 3 3 3 6
4 3 3 2 5
5 3 3 1 4
EOD
set xrange [0:6]
set yrange [0:4]
unset key
set style arrow 3 heads size 0.05,90 lc variable
splot $inputdata using 1:2:3:2 with linespoints pt 7 lc variable, \
$inputdata using 1:2:4:(0):(0):($5-$4):2 with vectors arrowstyle 3
pause -1
Thanks.

Related

gnuplot: transform axis of matrix plot with "every"

I have a problem with plotting matrices with gnuplot. I am plotting one row of matrix with every option like that
plot inputfile matrix every 1:1:(4+N*M+1):100:(4+N*(M+1)):100 with linespoint
where 100 is number of row. It gave me that result:
nearly good result
I would like to get xrange from 0 to 360, but when I use something like that
plot inputfile matrix using ($1*11.25):2 every 1:1:(4+N*M+1):100:(4+N*(M+1)):100 with linespoint
it doesen't work: wrong result
What can I do with it?
You don't provide data, so I create some for the following example.
As I understand you want to plot a certain row of a matrix and adjust the x-range.
Check help matrix every.
For example, in plot FILE u 1:2:3 matrix, 1 is the column, 2 the row and 3 is the (z)-value.
And in plot FILE u 1:3 matrix every ::c:r:c:r, c is the column and r is the row (counting starts from 0).
So the example below plots the 4th row and the x-range is adjusted from 0 to 360.
Code:
### plotting a certain row while adjusting the x-range
reset session
$Data <<EOD
1 2 3 4 5 6 7
2 3 4 5 6 7 8
3 4 5 6 7 8 9
4 5 6 7 8 9 10
5 6 7 8 9 10 11
EOD
set key top left
plot $Data u ($1*60):3 matrix every :::3::3 w lp pt 7
### end of code
Result:

How to set different heights for separate plots using multiplot

How can one set different heights for two or more plots in multiplot-mode using set size <x>,<y> respecting correct arrangement for the x-axes of the plots? Following problem: I've got a heatmap plot and another linespoint plot with the same time axis. The heatmap plot contains way more information and should use e.g. 80% of the canvas height. Using
set multiplot layout 2,1 margins .1,.8,.05,.95 spacing .05
sets the plots in perfect arrangement but without the possibility to change heights; or at least I didn't manage to get it right. Here are two examples using code from the gnuplot demopage:
$map2 << EOD
0 0 5
0 1 4
0 2 3
0 3 1
0 4 0
1 0 2
1 1 2
1 2 0
1 3 0
1 4 1
2 0 0
2 1 0
2 2 0
2 3 1
2 4 0
3 0 0
3 1 0
3 2 0
3 3 2
3 4 3
4 0 0
4 1 1
4 2 2
4 3 4
4 4 3
EOD
set multiplot layout 2,1 margins .1,.8,.05,.95 spacing .05
plot '$map2' using 2:1:3 with image
plot sin(x)*cos(x)**2, tan(x)
unset multiplot
which results:
Setting explicit sizes and origins before the plotting commands doesn't have any effect.
Plotting without the margins/spacing option and instead setting explicit sizes and origins for each plot one could only guess the correct x-width for the second plot. Guessing it between .85 and .9 in the code:
$map2 << EOD
0 0 5
0 1 4
0 2 3
0 3 1
0 4 0
1 0 2
1 1 2
1 2 0
1 3 0
1 4 1
2 0 0
2 1 0
2 2 0
2 3 1
2 4 0
3 0 0
3 1 0
3 2 0
3 3 2
3 4 3
4 0 0
4 1 1
4 2 2
4 3 4
4 4 3
EOD
set multiplot layout 2,1
set size 1,.75
set origin 0.025,.25
plot '$map2' using 2:1:3 with image
set size .85,.25 # <---
set origin 0.025,0
plot sin(x)*cos(x)**2, tan(x)
unset multiplot
lets me plot it like that:
I hope I could explain my question and thanks a lot for your help! It is highly appreciated!
If I have understood your question, you have to only change rmargin and lmargin:
set size 1,1
set origin 0,0
unset bmargin, unset lmargin, unset tmargin, unset rmargin
set multiplot
set size 1,0.8
set origin 0,0.2
set lmargin at screen 0.1
set tmargin at screen 0.95
set rmargin at screen 0.9
plot 'map2.dat' using 2:1:3 with image
set size 1,0.2
set origin 0,0
set tmargin 0
set lmargin at screen 0.1
set bmargin at screen 0.1
set rmargin at screen 0.9
plot[GPVAL_X_MIN:GPVAL_X_MAX] sin(x)*cos(x)**2, tan(x)
unset multiplot

image style plot issue with latest gnuplot 5.0.3

Recently I upgrade gnuplot to 5.0.3 and find that image style plot generate strange output with none square data. This does not happen in previous version (5.0.2). here is the minimal example
set term png
set output "a.png"
plot "-" using 1:2:3 with image title ""
#data
1 1 2
1 2 3
1 3 1
2 1 1
2 2 2
2 3 3
3 1 8
3 2 6
3 3 4
4 1 8
4 2 6
4 3 4
the output image is a.png
When dealing with square data like this
set term png
set output "b.png"
plot "-" using 1:2:3 with image title ""
#data
1 1 2
1 2 3
1 3 1
2 1 1
2 2 2
2 3 3
3 1 8
3 2 6
3 3 4
everything is fine b.png
is this a bug?
This may be a problem of sorting.
Try to sort by 2nd column like this:
1 1 2
2 1 1
3 1 8
4 1 8
1 2 3
2 2 2
3 2 6
4 2 6
1 3 1
2 3 3
3 3 4
4 3 4
I am facing the same problem. At the moment, I switch the x and y axes. I use "u 2:1:3 w image" instead of using "u 1:2:3 w image"

gnuplot hypertext is not working

I have the below gnuplot script, I'm trying to display the third column when the mouse hover over a point of the plot.
set title "Cloud"
set xlabel "Date"
set ylabel "Number"
filename ='data.dat'
stats filename using 4 nooutput
set xdata time
set timefmt '%Y-%m-%d'
set format x '%Y'
rand_x(x) = x + 60*60*24*7 * (rand(0) - 0.5)
rand_y(y) = y + (rand(0) - 0.5)
set xrange [ "1995-01-19":"2013-12-12" ]
plot for [i=0:int(STATS_max)-1] filename \
using (rand_x(timecolumn(1))):(i < $4 ? rand_y($2) : 1/0):3 pointtype 7 linecolor palette notitle
u 0:1:2 with labels hypertext point pt 7 ps var lc rgb "#ffee99"
And the data file looks like below:
1999-01-19 21 0 1
2009-07-01 0 1 1
2008-08-20 2 1 1
2008-12-18 1 1 1
2004-05-12 4 1 1
2009-07-29 2 1 1
2008-08-07 0 1 1
2006-03-08 1 1 1
2004-08-31 9 1 1
2001-03-27 12 1 1
2009-08-19 0 1 1
2010-07-14 2 1 1
2009-06-24 0 1 1
2009-11-11 0 1 1
2010-10-13 0 1 1
2012-02-22 0 1 1
2011-05-11 0 1 1
2011-03-03 0 1 1
2011-09-21 0 1 1
2011-12-20 0 1 1
2011-10-05 0 1 1
2012-05-03 0 1 1
2011-10-05 0 2 1
2013-01-09 0 2 1
2011-06-03 0 2 1
So can you please tell me what's wrong with my script?
Thanks.
First a remark for the readers: hypertext works only with the 4.7 development version.
To your problem: For plotting the labels, you must also use the same x and y columns 1 and 2 (you use 0 and 1). And you need the third column for the labels and a fourth one for the ps var. So your plot part for the labels is:
plot for [i=0:int(STATS_max)-1] filename \
using (rand_x(timecolumn(1))):(i < $4 ? rand_y($2) : 1/0):3 pointtype 7 linecolor palette notitle,\
'' u 1:2:3:3 with labels hypertext point pt 7 ps var lc rgb "#ffee99"

gnuplot | 3D layers

I have the below data file which has:
1st column is the layer number.
2nd column is the X axis.
3rd column is the Y axis.
1 1999-01-19 21 0 1
1 2009-07-01 0 1 1
1 2008-08-20 2 1 1
1 2008-12-18 1 1 1
2 2004-05-12 4 1 1
2 2009-07-29 2 1 1
3 2008-08-07 0 1 1
4 2006-03-08 1 1 1
4 2004-08-31 9 1 1
4 2001-03-27 12 1 1
My questions:
1. How can I plot the above data file in 3D knowing that each layer must have different Z offset and different color?
the below must be plotted with Z=1
1 1999-01-19 21 0 1
1 2009-07-01 0 1 1
1 2008-08-20 2 1 1
1 2008-12-18 1 1 1
and the below with Z=2
2 2004-05-12 4 1 1
2 2009-07-29 2 1 1
and so on.
2.If I want to select the layer number 2, other layers must be shaded with gray and this layer must be colored with red for example, is that possible? so it's like highlighting the selected layer.
thx.
To plot the points just use
set xdata time
set timefmt '%Y-%m-%d'
set format x '%Y'
splot 'data.dat' using 2:3:1
That uses the layer number as z-value. To get something else, just specify a function for the z-value depending on the layer number:
zpos(z) = 1 + 0.5*z
splot 'data.dat' using 2:3:(zpos($1))
For the coloring use linecolor rgb variable. That allows you to specify the color in the last column. This color must be the integer representation of an rgb-tuple which is 65536*red + 256*green + blue, with red, green and blue being in the range [0:255].
The following script plots the points in layer 2 in dark red:
set xdata time
set timefmt '%Y-%m-%d'
set format x '%Y'
rgb(r,g,b) = 65536*r + 256*g + b
gray = rgb(200,200,200)
red = rgb(200,0,0)
layer = 2
set view 66,20
splot 'data.dat' using 2:3:1:($1 == layer ? red : gray) with points pt 7 linecolor rgb variable notitle
The result with 4.6.4 is:

Resources