gnuplot heat map color range - dictionary

I have some X Y Z data in a file and I'm using gnuplot to display it.
I am creating a heat map, ie. a 2D plot where the Z value is presented using color.
Right now I'm using the following script:
set palette defined (0 "blue", 1 "red")
plot "xyz.dat" u $1:$2:$3 w image
My problem is, gnuplot ignores the 0 and 1 in the palette definition. It uses the colors specified, but rescales according to the minimal and maximal Z value in the file.
This makes it hard to visually compare different plots whose z range is different.
How do I tell gnuplot to stop rescaling the z color range?

The "set palette defined" command maps the grey values that you would get if you were plotting using greyscale onto a color palette; the scaling to min -> 0 and max -> 1 is how it's supposed to work. If you want to make a set of plots all with the same scaling of the data, you want to use the "set cbrange" command. For example,
set cbrange [0:0.5]
set palette defined (0 "blue", 1 "red")
splot '++' using 1:2:(sin($1)*cos($2)) w image
gives you an image plot with the maximum data value of 0.5 mapped to red and 0 mapped to blue.
Subsequent plots, like
splot '++' using 1:2:(0.5*sin($1)*cos($2)) w image
will use the same scaling, so they can be compared.

Related

gnuplot: how to set the size of the points according to the grid

I have the following 'data.dat' file:
# x y z radius
-1.64905083 -1.14142799 -2657.88232 177.358566
-449.735321 416.586914 -2865.25366 10.0000000
178.955292 -256.291138 -2856.96069 89.9588394
-336.942322 184.932343 -2839.22876 90.6131058
-443.635315 -80.0183029 -2863.29077 70.7404404
236.385406 349.893188 -2901.33984 10.0000000
485.313416 -366.513947 -2868.35083 10.0000000
with the positions of the spheres and their radii.
My file.p reads:
set terminal png size 500,500
set output 'file.png'
set multiplot
set xrange [-1000:1000]
set yrange [-1000:1000]
set zrange [-3000:-2500]
splot "data.dat" using 1:2:3:4 ps variable pt 7
splot -(3000**2-x**2-y**2)**(0.5)
but the dots that gnuplot provides me are much bigger.
I understand that it is because ps yields points that are radius times bigger than the normal size.
Meaning that ps does not allow to set the radius of the dots, but rather how many times bigger it is than the normal points.
How can I set the radius of the points please ?
Use "with circles" rather than "with points pt 7".
From the manual:
gnuplot> help with circles
The `circles` style plots a circle with an explicit radius at each data point.
The radius is always interpreted in the units of the plot's horizontal axis
(x or x2). The scale on y and the aspect ratio of the plot are both ignored.
If the radius is not given in a separate column for each point it is taken from
`set style circle`. In this case the radius may use graph or screen coordinates.
Many combinations of per-point and previously set properties are possible.
For 2D plots these include
using x:y
using x:y:radius
using x:y:color
using x:y:radius:color
using x:y:radius:arc_begin:arc_end
using x:y:radius:arc_begin:arc_end:color
By default a full circle will be drawn. It is possible to instead plot arc
segments by specifying a start and end angle (in degrees) in columns 4 and 5.
A per-circle color may be provided in the last column of the using specifier.
In this case the plot command must include a corresponding variable color
term such as `lc variable` or `fillcolor rgb variable`.

How to use GnuPlot to create a plot of droplets of size d versus height and color the droplets by size?

I have a file of x,y,z,d Where x,y,z are the coordinates of a droplet and the diameter of the droplet is d.
I want to do a GnuPlot of the x, z position of the droplet and color it by the diameter from the RGB spectrum scaled from the minimum d to the maximum d.
I have tried using this:
unset hidden3d
set ticslevel 0.5
set view 60,30
set autoscale
set parametric
set style data points
set xlabel "data style point - no dgrid"
set key box
set output 'particles.png'
plot '/directory/kinematicCloud_00000490.dat' \
using 1:3:(0.5-rand(0)):(5.*rand(0)) with points pt 5 ps var lc rgb variable
pause -1
But, the points are being colored here by random colors. I'd like them colored as I said above. So, how do I specify the 3rd and 4th argument to do what I wish?
# Set palette to RGB spectrum (Red = Min; Blue = Max)
set palette model HSV defined (0 0 1 1, 1 0.7 1 1)
# Set min/max of color spectrum to match expected droplet size
set cbrange [0 : MAX]
# 3D plot with points colored by diameter
splot 'data' using 1:2:3:4 with points pointtype 7 lc palette
If you want to discard the y coordinate and make a 2D plot instead, then the command becomes
# 2D plot x/z with points colored by diameter
set view map
splot 'data' using 1:3:(0):4 with points pointtype 7 lc palette

GnuPlot line plot from data points, z interpolated color?

I have a data file with x, y, and z datums--basically x,y locations with
z representing attenuation at that location.
The answer to a question like Line plot in GnuPlot where line color is a third column in my data file? using
palette defined (with palette z) is very
close, except that each line segment is set to a single color along its length.
Is there a
way to have the Z value interpolated (linear is fine) along each segment, so
the attenuation values are a smooth gradient rather than jumping values
at each segment boundary?
You can use set dgrid3d to interpolate a given data set. Consider the data file test.dat with the content
1 2 1
2 3 2
1 1 2
Plot this with
set dgrid3d 30,30 splines
set ticslevel 0
set hidden3d
splot 'test.dat' matrix w l lc palette lw 3
to get
If this works also in your case depends on several other factors, like number of data points or if you don't want to create a new grid, but retain the original grid, and only smooth the colors. In the latter case you must write an external script to prepare your data in an appropriate way.

Anyone have a way to plot a bean plot in gnuplot?

Title is pretty self explanatory but here is a picture of what I'd like to do. I'm having a tough time figuring out if its even possible.
Plot borrowed from:
Evaluation of geochemical background levels around sulfide mines – A new statistical procedure with beanplots. Gusstavason et al. 2012.
Doing the plot in exactly this orientation could be very cumbersome, if possible at all.
My suggestion is to plot everything with the usual orientation (i.e. having the 'sediments' axis as x-axis, or rather as x2-axis), rotate all labels a bit and finally rotate the complete output by 90 degree (pdf file with e.g. pdftk etc).
With this you can use any plot style as usual. In the script below I just show you how to plot the violet and yellow filled curves (using pseudo data) for two different data sets. Adding the other peaks should be straight forward (plot the bars with e.g. boxes or vector plotting style).
In order to have distinct ytics for the different plots, I associated a certain y-value with a certain plot, 1=Water, ..., 4=Gyttja).
Putting all toghether gives the following script:
reset
set terminal pdfcairo linewidth 2
outfile='bean'
set output outfile.'.pdf'
set encoding utf8
set x2range [0.5:9000]
set logscale x2
set x2tics (1, 5, 10, 50, '' 100, 500, '' 1000, 5000) out
set x2label 'mg/kg (sediments), µg/L (water)'
unset xtics
set yrange[0.5:4.5]
set ytics ('Water' 1, 'Minerogenic' 2, 'Peat' 3, 'Gyttja' 4) center rotate by -90 out
set label at graph 0.95, graph 0.05 right rotate by -90 'Nickel' font ',20' front
# cover possible data overlapping with the label
set object rectangle from graph 0.9, graph 0 to graph 1,graph 0.2 fillcolor rgb 'white' fillstyle solid noborder front
unset key
set macros
fs1="fillcolor rgb '#fc9e00' linewidth 2 fillstyle solid border lt -1"
fs2="fillcolor rgb '#9119f7' linewidth 2 fillstyle solid border lt -1"
# use pseudo data
set samples 500
plot '+' using 1:(4-0.3*exp(-(($1-10)/5.0)**4)) axes x2y1 with filledcurves y1=4 #fs1,\
'' using 1:(4+0.2*exp(-(($1-70)/50.0)**4)) axes x2y1 with filledcurves y1=4 #fs2,\
'' using 1:(1-0.4*exp(-(($1-5)/2.0)**2)) axes x2y1 with filledcurves y1=1 #fs1,\
'' using 1:(1+0.1*exp(-(($1-30)/20.0)**2)) axes x2y1 with filledcurves y1=1 #fs2
set output
system(sprintf('pdftk %s.pdf cat 1W output %s-rot.pdf', outfile, outfile))
system(sprintf('pdftocairo -r 150 -png %s-rot.pdf', outfile))
This gives (conventional and rotated output side-by-side) with 4.6.3:
Some stuff is required for the pseudo data. For a real data file, the plotting line looks a bit differently. The different plots have a separation of 1 in y-direction, so you must scale your data accordingly (done here manually with a scaling factor sc):
sc = 5.1
plot 'datafile.txt' using 1:(4 + $2/sc) axes x2y1 with filledcurves y1=4 #fs1
You can of course also do the scaling automatically, by extracting some minimum/maximum values using the stats command.

gnuplot: Points overlap in pm3d with a wide xrange

I'm using gnuplot to plot three dimentions of data using pm3d. I'm trying to plot the number of times an event occurs (z value) with respect to the day of the year (x value) and hour of the day (y value).
Using pm3d works great for up to a range of 600 (rought 2 years of data). However, the points begin to overlap each other when a wider range is required.
I believe this is related to the fact that gnuplot isn't stretching the plot to the full size specified in set terminal. I haven't however been able to find a setting that controls this directly.
the script I'm using:
set terminal png size 10000, 1000
set output "%s_plot.png"
set title "%s's"
set ytics 1,1
set xtics 1
set xrange[0:%s]
set yrange[0:23]
set cbrange[0:%s]
set pm3d map
set palette defined (0 "white", 1 "blue", 31 "red")
splot '%s.data'
aspect of the plot for a range of [0:1000] in x:
aspect of the plot for a range of [0,100] in x:
(the images above are just snippets of the whole thing)
What can I do to remedy this? Perhaps the solution is manually setting the points (squares) to have a fixed width.
Thanks.
For the kind of plot that you want, I would replace your last line with:
plot '%s.data' matrix with image

Resources