how can set different type of data to different colorbars in a plot by gnuplot? - gnuplot

I want to plot some data that belongs to 10 different classes with different 10 color-bars, I scaled each classes to lie in different intervals. but this code has some errors:
warning:
Number of pixels cannot be factored into integers matching grid. N = 5999 K = 60
code:
anyone can help me?
every help is appreciated.
unset key
set terminal eps enhanced
set output "t62.eps"
set xrange[0:0.5]
set yrange[0:6]
set palette model RGB
set palette model RGB defined (0 "green", 1 "dark-green", 1 "yellow", 2 "dark-yellow", 2 "red", 3 "dark-red" , 3 "blue" , 4 "dark-blue" )
set cbrange [ 0.00000 : 10.00000 ] noreverse nowriteback
set pm3d explicit at b
set palette defined ( 0 '#7FFF00', 1 '#008000', 1 '#FFFF00', 2 '#FF8C00', 2 '#FF0000', 3 '#800000', 3 '#DDA0DD', 4 '#4B0082', 4 '#B0C4DE', 5 '#191970', 5 '#00BFFF', 6 '#00008B', 6 '#C0C0C0', 7 '#000000', 7 '#FFEFD5', 8 '#8B4513', 8 '#BDB76B', 9 '#556B2F', 9 '#40E0D0', 10 '#2F4F4F' )
plot 'opplot2.txt' u 2:1:4 w image

Related

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

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.

gnuplot stacked bar chart arithmetic

tmp.data
DATE D0 D1 D2 D3 D4 D5
"2017-07-19" 10 8 6 4 2 1
"2017-07-20" 16 14 10 11 10 9
"2017-07-21" 6 5 4 4 3 1
"2017-07-22" 7 5 4 4 3 2
"2017-07-23" 8 6 4 2 1 1
tmp.gnu
set terminal png size
set output 'output.png'
set title "statistics"
set key font ",10"
D0 = "#99ffff"; D1 = "#4671d5"; D2 = "#ff0000"; D3 = "#f36e00"; D4 = "#8A2BE2#'; D5 = "#4671d5"
set auto x
unset xtics
set xtics nomirror rotate by -45 scale 0
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75
plot 'tmp.data' u 2:xtic(1) title columnheader, \
'' u 3:xtic(1) title columnheader, \
'' u 4:xtic(1) title columnheader, \
'' u 5:xtic(1) title columnheader, \
'' u 6:xtic(1) title columnheader, \
'' u 7:xtic(1) title columnheader
Creates the following:
The columns are accumulative.
What I'd like to have is have it proportional, for example in row 2.
10 - 8 = 2,
8 - 6 = 2,
6 - 4 = 2,
4 - 2 = 2,
2 - 1 = 1
If you want to plot the difference between two columns, then you must calculate the difference inside the using statement like
plot "tmp.data" using ($2 - $3):xtic(1)
to plot the difference between third and second column. For all your columns, and keeping the second as is, use (using the inline data $data requires 5.0):
$data <<EOD
DATE D0 D1 D2 D3 D4 D5
"2017-07-19" 10 8 6 4 2 1
"2017-07-20" 16 14 10 11 10 9
"2017-07-21" 6 5 4 4 3 1
"2017-07-22" 7 5 4 4 3 2
"2017-07-23" 8 6 4 2 1 1
EOD
set xtics nomirror rotate by -45 scale 0
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75
set key auto columnheader
plot $data u 2:xtic(1), \
for [i=3:7] '' u (abs(column(i) - column(i-1))):xtic(1)
Here, you must decide if you need the abs or not. The result is:

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

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:

Heatmap with Gnuplot on a non-uniform grid

I would like to create a heatmap with gnuplot based on a non-uniform grid, meaning that my x axis bins do not have all the same width, and I can't figure out how to do that because when I plot my data with for example "with image" I get uniformly sized boxes which do no correspond to my coordinates at all (because "image" treats the data just as matrix I guess). So I would like to find a method to get non-uniform boxes which are also positioned in the right place on the Cartesian plane.
My data look something like this:
1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2
2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1
5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9
7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6
If I run this command on Gnuplot
set xrange [1:10]
p 'mydata.dat' with image
I get an image with 16 boxes that have the same width and height (apparently I don't have enough "reputation" on Stackoverflow to post an image, otherwise I would), but ideally I would like the boxes to have different widths and be in the right place on the plane. For example the first box should range from 1 to 2, the second one from 2 to 5, the third one from 5 to 7, and the last one from 7 to 10 (which is why I wrote set xrange [1:10]).
Could anyone help me please? Thank you very much!
The easiest (maybe only viable) way is to add some dummy data points and use splot ... with pm3d. This plotting style handles heatmaps with general quadrangles.
The image plotting style plots one box (one big pixel) for each data point, while pm3d takes each data point as corner of one or more quadrangles. The color of each quadrangles is determined by the values of the corners and is adjustable with set pm3d corners2color.
So, in your case you need to expand the 4x4 matrix to a 5x5 matrix (expand to right and top), but select the lower left corner to determine the color set pm3d corners2color c1.
The changed data file is then:
1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2
1 5 0.5
2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1
2 5 0.5
5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9
5 5 0.5
7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6
7 5 0.5
10 1 0.5
10 2 0.5
10 3 0.5
10 4 0.5
10 5 0.5
To plot it use
set pm3d map corners2color c1
set autoscale fix
set ytics 1
splot 'mydata.dat' using 1:($2-0.5):3 notitle
The result with 4.6.3 is:
In general, the z-value of the dummy data points doesn't matter, but in the above script it should lay somewhere between minimum and maximum values to allow set autoscale fix to work properly on the color scale.
If you don't want to change the data file manually, you could do it with some script, but that's a different question.
Here is an alternative solution without splot ... pm3d, but with boxxyerror.
If you plot data it should go as automatic as possible and there should be no need to "invent" and manually add data.
The following solution (a little bit more complex) takes care about the widths (+/-dx) and heights (+/-dy) of the boxes according to the following principle:
if it is an "inner" box, take half the distance to the adjacent datapoint on that side
if it is an "outer" box, take half the distance to the adjacent "inner" datapoint
Here, x-distances are irregular and y-distances are regular, but y-distances could also be irregular.
Data: SO19294342.dat
1 1 0.2
1 2 0.8
1 3 0.1
1 4 0.2
2 1 0.7
2 2 0.2
2 3 0.3
2 4 0.1
5 1 0.2
5 2 0.4
5 3 0.1
5 4 0.9
7 1 0.3
7 2 0.2
7 3 0.9
7 4 0.6
Script: (works with gnuplot>=4.6.0, March 2012)
### heatmap with boxxyerror and variable box-sizes
reset
FILE = "SO/SO19294342.dat"
set style fill solid 1.0
set tics out
set size ratio -1
# extract x-positions
Xs = Ys = ''
Nx = Ny = 0
b = -1
stats FILE u (column(-1)!=b ? (Nx=Nx+1, Xs=Xs.sprintf(" %g",$1), b=column(-1)) : 0, \
column(-1)==0 ? (Ny=Ny+1, Ys=Ys.sprintf(" %g",$2)) : 0) nooutput
d(vs,n0,n1) = abs(real(word(vs,n0))-real(word(vs,n1)))/2
dn(vs,n) = (n==1 ? (n0=1,n1=2) : (n0=n,n1=n-1), -d(vs,n0,n1))
dp(vs,n) = (Ns=words(vs), n==Ns ? (n0=Ns-1,n1=Ns) : (n0=n,n1=n+1), d(vs,n0,n1))
plot FILE u 1:2:($1+dn(Xs,column(-1)+1)):($1+dp(Xs,column(-1)+1)):\
($2+dn(Ys,int(column(0))%Ny+1)):($2+dp(Ys,int(column(0))%Ny+1)):3 w boxxy palette notitle
### end of script
For gnuplot>=4.6.5 you could add :xtic(1):xtic(2) to the plot command to only show your x- and y-coordinates as x,y-ticlabels.
plot FILE u 1:2:($1+dn(Xs,column(-1)+1)):($1+dp(Xs,column(-1)+1)):\
($2+dn(Ys,int(column(0))%Ny+1)):($2+dp(Ys,int(column(0))%Ny+1)):3:\
xtic(1):ytic(2) w boxxy palette notitle
And for gnuplot>=5.0.0 you could add noextend to the ranges to avoid white areas on the sides:
set xrange[:] noextend
set yrange[:] noextend
Result: (created with gnuplot 4.6.0)

Resources