I have a rather specific problem. I want to plot a electronic difference density using splot. The gridfile contains values from around -5 to up to 25. However, I am only interested in small values to find nodelines. So I would like to set palette such, that everything that is smaller/larger than the lower/upper boundary has the boundary color.
Here is what I use:
set key off
set view map
set palette defined (-0.01 'blue', 0 'white', 0.01 'red')
splot [][][-0.01:0.01] 'gridfile.dat' matrix with points pointtype 5 palette
That gives me almost what I want - but instead of coloring the out of range points with the colors of the boundaries gnuplot just does nothing (so I get the color of the background there).
I tried fiddling around with cbrange, because according to the manual, that should do what I need:
Cbrange
The set cbrange command sets the range of values which are colored using the current palette by styles with pm3d, with image and with palette. Values outside of the color range use color of the nearest extreme.
However, that has not worked so far and I am running out of ideas (and out of possible google-searches).
Does anybody know how I could solve this?
set cbrange is indeed what you are looking for, but not what the third bracket pair [-0.01:0.01] for splot does: that is the zrange. Use
set key off
set view map
set palette defined (-0.01 'blue', 0 'white', 0.01 'red')
set cbrange [-0.01:0.01]
splot 'gridfile.dat' matrix with points pointtype 5 palette
I want to create a simple histogram in gnuplot and want to adapt the color of the bars according to the data. Currently, I am struggling with the mapping between color and data.
Let's say I have the following data file:
X, 500.00, 100.00, 1
Y, 600.00, 200.00, 2
I generate the histogram with the following code:
reset
fontsize = 12
set terminal png
set output "file.png"
set style fill solid 1.00 border 0
set style histogram errorbars gap 2 lw 1
set style data histogram
set xtics rotate by -45
set grid ytics
set xlabel "label"
set ylabel "label"
set yrange [0:*]
set datafile separator ","
plot 'data.dat' using 2:3:4:xtic(1) ti "" lc variable
Now I want to create a mapping between the fourth column in the data and the color, e.g. 1 -> yellow, 2 -> blue.
I assumed that I can define something like the following
set style line 1 linecolor rgb "yellow"
set style line 2 linecolor rgb "blue"
but this code is not working since it defines styles and not colors. On the other hand I have read in the documentation that "rgb variable" is only available in 3D plotting mode (splot), so I think in this terms my whole approach might go in a wrong direction.
Does anyone know how to realise the mapping between data and line colors?
Have you tried with the command palette? I had the same problems some times ago. I wanted to make this plot (that is in some ways what you need)
So I used the number of elements in a column of the histogram to set the color of that column. My datafile looked like
#MY_FILE
...
26 0.02302 2302
28 0.02233 2233
30 0.02261 2261
32 0.02383 2383
34 0.02279 2279
36 0.02366 2366
38 0.02226 2226
40 0.02148 2148
...
#EOF
where the first row $1 was the n parameter, the second one $2 was my pdf (simply the histogram normalized) and the third $3 column was the number of occurrence int the bin. Then I used the last column as the parameter to color my graph with the command
set palette model RGB defined (1 "blue", 2 "red")
that create a gradient between the starting point 1 and the end 2. Then to use the palette i plotted with the line
p 'MY_FILE' u 1:2:3 w boxes palette
where the w boxes was the command to generate my histogram, and the palette (also pal) command was the command o set the color, which use the third column as specified in u 1:2:3, where the 1:2 is my histogram and 3 is the color gradient.
if you don't want the lateral strip of color (heatmap) just type in gnuplot
unset colorbox
Here's some documentation about palette command in gnuplot:
http://gnuplot.sourceforge.net/demo_5.0/pm3dcolors.html
type help palette on gnuplot
THIS could be particularly HELPFUL: http://www.gnuplotting.org/defining-a-palette-with-discrete-colors/
As I said I have 2D matrix 68 per 68 and I want to make a heat map from it.
Each value in the matrix should be displayed as a separate cell. Every fourth cell should be labelled as "XXX\n715" 0, "XXX\n718" 3 and so on...
This is my plot: https://www.dropbox.com/s/tiipsn5mhmbnb5b/TEST.png?dl=0
Data used to produce this plot can be found here: https://www.dropbox.com/s/izrfbm157q1tedj/matrix.dat?dl=0
At present, I can see two problems with my plot:
1.) Cells are too small. Therefore, the plot is hard to read.
I want to increase size of a cell 2 times.
If I understand correctly, each pixel corresponds to one value?
If so, I would like to increase size of a pixel. That's way I was thinking
about drawing a grid size of 68*2/68*2, so that each value in my matrix will
be displayed in a 2-pixel/2-pixel-square box (cell).
2.) Values are outside cells's borders.
I had the same problem with smaller 2D arrays and I fixed it by trying
different resolutions (terminal size). I have been trying to apply a discussed
solution for the 68x68 matrix, but it did not work for me.
I tested many different scripts and I am stuck on these problems.
Thank you.
Code below:
set terminal png transparent truecolor nocrop enhanced size 800,800 font
"arial bold,8”
set output 'TEST.png'
set size ratio 1
set palette rgbformulae -21,-22,-23
# drawing grid
set x2tics 1 format '' scale 0,0.001
set y2tics 1 format '' scale 0,0.001
set mx2tics 2
set my2tics 2
# labels
set xtics 3 out nomirror
set ytics 3 out nomirror
set grid front mx2tics my2tics lw 0.5 lt 1 lc rgb 'black'
set xrange[-0.5:67.5]
set yrange[-0.5:67.5]
set x2range[-0.5:67.5]
set y2range[-0.5:67.5]
set xtics add ("XXX\n715" 0, "XXX\n718" 3)
set ytics add ("XXX\n715" 0, "XXX\n718" 3)
plot "matrix.dat" matrix w image noti
I am plotting data as described in a previous Stackoverflow question:
gnuplot 2D polar plot with heatmap from 3D dataset - possible?
Mostly it is working well for me, and I am down to some small details. One of these is how to exert control over the contour line colors and linewidths. There are lots of posts on the web regarding using set style increment user followed by definition of user style via set style line 1 lc rgb "blue" lw 2 etc. In theory this was supposed to force splot to plot lines using the newly defined styles. I tried it and it did not work. In addition, when I went to the help pages through my gnuplot install, I discovered that this usage is deprecated with my version (Version 4.7 patchlevel 0 last modified 2013-07-25). It was recommended to use set linetype instead, which changes the characteristics of the gnuplot line style permanently for the current invocation of gnuplot. Killing and restarting gnuplot restores the default linetype characteristics.
Next, I restarted gnuplot, regenerated the plot without redefining any line style or type for the contour lines. When I looked at my plot, I could see that the line colors start with cyan, then purple, then blue (e.g. like line types 5,4,3 or 14,13,12, etc.). It seems as if the line types are going BACKWARDS through the available styles. OK, I thought, I can just change those and live with the odd behavior. However, after issuing multiple set linetype commands that changed all of these line types to something that would be obviously different (I verified these by running the test command, the contour lines on the plot still had the same color and line width as before. I can't seem to figure out what linetype is being used for the contour lines, so I can't change the appropriate linetype.
Perhaps this odd behavior is a result of the contour line being of type set cntrparam levels increment -6,-6,-24 and the negative values and/or negative going increment are causing some unpredictable behavior?
I'd like to know how I can know what line type will be used for contour lines in this plot, and whether that will change if the number of lines used to build the surface plot change. For instance, the plot shown below uses 13 "lines" to generate the surface using set pm3d map. So let's say N=13 lines - is there a rule that is obeyed for the first contour linetype?. For instance, will I always be sure that the contour line style will start at N=14? I'd to know what line type will be used for the first and subsequent contour lines when the number of "lines" in my input data will vary.
The bottom line is that I need to apply certain style to the contour lines used for each contour level. I want to consistently use the same style for each level when the input data changes. The plot will always use the same set of contour levels: -6, -12, -18, and -24. The plot data will always have a maximum "z" coordinate of about 0 and decrease from there.
Gnuplot commands are shown below. The dataset for this plot can be downloaded here:
http://audio.claub.net/temp/new_test.dat
reset
set terminal pngcairo size 800,800
set output '3d-polar.png'
set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set pm3d map interpolate 20,20
unset key
set multiplot
# plot the heatmap
set cntrparam bspline
set cntrparam points 10
set cntrparam levels increment -6,-6,-24
set contour surface
#set style increment user #NOTE: the commented out lines do not seem to affect color or width of the the contour lines no matter what number I use for the linetype
#set linetype 8 lc rgb "blue" lw 2
#set linetype 9 lc rgb "black" lw 1
#set linetype 10 lc rgb "orange" lw 1
#set linetype 11 lc rgb "yellow" lw 1
set palette rgb 33,13,10 #rainbow (blue-green-yellow-red)
set cbrange [-18:0]
unset border
unset xtics
unset ytics
set angles degree
r = 3.31 #This number is Log10(max frequency) - Log10(min frequency) of the polar frequency grid
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8
splot 'new_test.dat'
# now plot the polar grid only
set style line 11 lc rgb 'black' lw 2 lt 0
set grid polar ls 11
set polar
set logscale r 10
set rrange[10:20000]
unset raxis
set rtics format '' scale 0
#set rtics axis scale
set rtics (20,50,100,200,500,1000,2000,5000,10000,20000)
do for [i=-150:180:30] {
dum = r+0.15+0.05*int(abs(i/100))+0.05*int(abs(i/140))-0.05/abs(i+1)
set label i/30+6 at first dum*cos(i), first dum*sin(i) center sprintf('%d', i)
}
set label 20 at first 0, first -(log(20)/log(10)-1) center "20"
set label 100 at first 0, first -(log(100)/log(10)-1) center "100"
set label 200 at first 0, first -(log(200)/log(10)-1) center "200"
set label 1000 at first 0, first -(log(1000)/log(10)-1) center "1k"
set label 2000 at first 0, first -(log(2000)/log(10)-1) center "2k"
set label 10000 at first 0, first -(log(10000)/log(10)-1) center "10k"
set label 20000 at first 0, first -(log(20000)/log(10)-1) center "20k"
plot NaN w l
unset multiplot
unset output
The plot with no control over the contour lines is shown below. I need to be able to specify line color and width for the contour lines. How?
Here is how you can change the line properties of the contour lines. I can't explain why it is that way, I just found out by testing it. Unfortunately, there is no documentation about these details.
The behaviour is as follows (tested with 4.6.3. and 4.7 (2013-07-25 and 2013-09-09), all show the same behaviour):
Default settings
If no linetype is specified for splot, the surface itself would use lt 1. In that case the first contour is drawn with lt 3. Yes, the numbering is backwards compared to the specified increment. But you can reverse it by using set cntrparam levels increment -6,-6,-18 or set cntrparam levels increment -18,6,-6
The linewidth of all contours is the same and also equal to the linewidth used for the plotting command, to change it use e.g. splot 'new_test.dat' lw 3.
The result (without the thicker lines) is as shown in the question.
Using linestyles
The contours use the linestyle with an index by one higher than the one used by the plotting command.
You must also define the first linestyle, which would be used by the surface. If this style is not defined, the contours fall back to using linetype.
The linewidth is taken from the first linestyle, all lw settings from the following ls are ignored.
Using customized linetypes
The contours use the linetype with an index by one higher than the one used by the plotting command.
All linetype must be customized, also the first, the one used by the surface. Otherwise the default settings are used.
lw same as for linestyle.
For testing I used your data and the following stripped down script:
reset
set terminal pngcairo size 800,800
set output '3d-polar.png'
set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set pm3d map interpolate 20,20
# plot the heatmap
set cntrparam bspline
set cntrparam points 10
set cntrparam levels increment -6,-6,-18
set contour surface
set palette rgb 33,13,10
set cbrange [-18:0]
unset border
unset xtics
unset ytics
set angles degree
r = 3.31
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8
# load one of the following files:
#load 'linestyle.gp'
#load 'linetype.gp'
splot 'new_test.dat' title ' '
The cbrange is defined only down to -18, so I changed the contour levels accordingly (-24 wasn't drawn anyway).
The two 'contour settings files', which I use are:
linetype.gp:
set linetype 1 lc rgb "blue" lw 3
set linetype 2 lc rgb "black"
set linetype 3 lc rgb "orange"
set linetype 4 lc rgb "yellow"
linestyle.gp:
set style increment user
set style line 1 lc rgb 'blue' lw 3
set style line 2 lc rgb 'black'
set style line 3 lc rgb 'orange'
set style line 4 lc rgb 'yellow'
Both give the same output image:
To use this for your complete script, just load one of the two files directly before the splot command. This gives the output:
After your first question about contours, I was about to submit a bug report, but it turned out to be rather difficult to boil it down to concrete questions. With this question it might be easier. I'll see if I find some time to do this.
I had to refer back to this question when I was again doing some GNUplot plotting, this time in rectangular coordinates, and found that could not recall how to control the line type for contour lines.
I found that the info above is now not quite correct, and I have discovered a way to explain how this works as of GNUplot version 5 patchlevel 3.
There are three things I found to control the contour lines:
1. the 'set cntrparam levels increment' command, and
2. the command 'set style increment user', and
3. the list of line styles (I used the 'set style' command)
It turns out it's a little tricky. Let me give an example or two from my own code:
#HOW TO CONTROL LINE COLOR AND WIDTH FOR CONTOUR LINES:
#the number of contour lines and their level is controlled using the 'set cntrparam' command, above
#the 'set cntrparam' has the format 'start,increment,end' for the line positions
#note that the end level is listed at the top of the key/legend for the lines!
#line style 1 is used elsewhere, not for contour lines
#line style 2 is used for the style of the last line (e.g. end, or the last one drawn)
#line styles for other lines begins further down the list of styles and works UPWARDS to line style 2
#example 1: three lines at -40, -30, and -20
# set cntrparam levels increment -20,-10,-40
# set style line 1 lw 0.5 lc "grey30"
# set style line 2 lw 0.5 lc "blue"
# set style line 3 lw 0.5 lc "white"
# set style line 4 lw 0.5 lc "red"
# This results in:
# -20 line color is RED
# -30 line color is WHITE
# -40 line color is BLUE
#
#example 2: four lines at -35, -30, -25, and -20
# set cntrparam levels increment -20,-5,-35
# set style line 1 lw 0.5 lc "grey30"
# set style line 2 lw 0.5 lc "blue"
# set style line 3 lw 0.5 lc "white"
# set style line 4 lw 0.5 lc "red"
# set style line 5 lw 0.5 lc "yellow"
# This results in:
# -20 line color is YELLOW
# -25 line color is RED
# -30 line color is WHITE
# -35 line color is BLUE
I'm hoping that others will find this useful and informative. Perhaps Christoph (if he happens to read this thread) can comment, since GNUplot is an evolving tool and he would know about it in detail.
As a quick and dirty but easy solution, I sometimes relate all to only a single color:
set for [i=1:8] linetype i linecolor 0
When plotting color-maps using gnuplot, I usually use the following lines:
...
set palette rgbformulae 33,13,10
plot "file.dat" using 1:2:3 with points pointtype '7' palette
Usually the range of the third point (appearing in the legend) is automatically set by gnuplot. But how can I change that? say I want the range of the 3rd point to be from 0 to 1500.
Any suggestions?
This is actually a really good question -- assuming you mean that you want the colorbar range to be determined (not the legend [i.e. key] -- the legend doesn't typically have that information).
My first thought was set cbrange. This might do what you want --
set cbrange [0:1500]
set palette rgbformulae 33,13,10
plot "file.dat" u 1:2:3 w p pt 7 palette
However, the question is then "What do you want to happen to out of range points?" This solution will move out of range points to the bottom/top of the scale (e.g. purple for negative numbers, red for numbers greater than 1500). My next thought was that you should be able to clip those points out by set zrange [0:1500] -- But that doesn't work. You have at least 2 options at this point.
Option 1: use splot:
set view map
set cbrange [0:1500]
set zrange [0:1500]
set palette rgbformulae 33,13,10
splot "file.dat" u 1:2:3 w p pt 7 palette
Your borders will be slightly different than they were before, but that's no real big deal.
Option 2: filter with the ternary operator (which you already know about from your previous question):
set cbrange [0:1500]
set palette rgbformulae 33,13,10
inrange(c)=((c>=0) && (c<=1500))? c : (1/0)
plot "file.dat" u 1:2:(inrange($3)) w p pt 7 palette
Also, for plotting color maps, you may want to look into the pm3d plotting style (image might work too). You might need to restructure your datafile slightly, but plotting color maps is that plotting style's bread-and-butter.