I need to construct a discrete palette color with only a few colors, say:
set palette defined (0 'red', 1 'red', 1 'green',\
2 'green', 2 'blue', 3 'blue',\
3 'yellow', 4 'yellow')
which will be applied a specific number of times to a unique matrix data-file, i.e., by recycling the palette. Suppose the matrix data-file ranges integers data from 0 up to 16. The palette will be applied four times: first, for data in [0:4]; second, for [4:8], third, for [8:12] and fourth, for [12:16]. The final result I expect is a heat map (2D image) with four colors.
I have tried the following palette:
set palette defined ( (k%4==0)'red', (k%4==1)'red',\
(k%4==1)'green', (k%4==2)'green',\
(k%4==2)'blue', (k%4==3)'blue',\
(k%4==3)'yellow',(k%4==4)'yellow' )
where 'k' is the element of matrix data-file. My problem is to define 'k'.
Of course, it can be done by some coding on the data-file but I will lose original information.
Is there any way to define such "recycling palette"?
Leave the palette the way you have it and apply the cyclic repeat at the stage of data input. Original command:
set cbrange [0:4]
set view map
splot $data matrix using 1:2:3 with image
Data value filtered to cycle through palette mapped to [0:4]
splot $data matrix using 1:2:(floor($3)%4) with image
Related
I used to make nice pm3d maps with gnuplot with a simple code like this:
set pm3d map
set palette
splot data using 1:2:3
But that had data organized as follows:
1 1 1
1 2 1
1 3 2
2 1 1
2 2 3
2 3 4
3 1 1
3 2 1
3 3 3
I never really understood the need for line break here but it worked. Now my data is quite different, the data in the first and second columns are not as simply repeated they are like this:
1.1 -1 2
1.2 3 3
1.11 4 4
...
I don't have any line breaks there since i have not idea how i should organise them. The question is, how would i make a heatmap from this? (rounding is not a good option)
Some sample data can be found here. They were created from an original 21x21 array (see below).
Some background
Originally, the data were in a table indexed by integers. It was basically a polar stereographic projection of the lunar surface. So i converted the indices to (x,y) distances then to planetocentric (latitude,longitude) pair and then to gnomonic polar coordinates recentered on a different point than one of the poles. I want to display the map as distance (x axis) and azimuth (y axis) (from the new centered point) and some value (the coloring of the map). The goal is to have something that looks like this:
The sample data you link to is highly structured, but not on an orthogonal grid. That is likely to produce artifacts. If the data were dense enough, you could simply draw each point as a solid block, perhaps with partial transparency. The example data you show is not very dense, however, so this is probably not suitable. I show such a plot below for reference.
set palette defined ( 0 "blue", 3 "green", 6 "yellow", 10 "red" )
set autoscale noextend
set pointsize 2
unset key
plot 'DT0C2.dat' using 1:2:3 with points pointtype 5 lc palette
The closest gnuplot has to dealing with unstructured sample is the dgrid3d mode. This basically uses the data points to assign value to nearby nodes on an orthogonal grid. Various weighting schemes are available to control how many data points contribute to each node and what is their relative contribution. The result is strongly dependent on choosing reasonable values for the orthogonal grid spacing and the weighting scheme. I won't attempt to describe all the options here. Please read the gnuplot documentation section on set dgrid3d. Here is a rough stab at it but I would want to understand the data a lot better to choose a good dgrid3d scheme. I think the sample data is not dense enough to produce a smooth result.
set palette defined ( 0 "blue", 3 "green", 6 "yellow", 10 "red" )
set autoscale noextend
set dgrid3d 75,75 gauss 100,25
set view map
splot 'DT0C2.dat' with pm3d
I'm plotting multiple transects together. With two transects plotted, the color scheme is what I'm looking for. When I plot a third, it changes. If I zoom in with three transects plotted, I again get the desired color differentiations. Why does it change like this? Is it a limit of gnuplot, my video card, monitor, or just my understanding of gnuplot?
I'm running a 4k monitor at 4k resolution on a 1.5GB Intel Iris graphics card on a 2015 MacBook Pro. There are ~8,000 - ~11,000 points in each transect.
Undesired color palette:
Desired color palette, with zoom:
My code:
reset
set object 1 rectangle from screen 0,0 \
to screen 1,1 fillcolor rgb 'black' behind
set view 49,15
set grid ztics
set palette model RGB
set palette defined (1 'cyan', 300 'blue', 650 'green', \
1500 'yellow', 3000 'red', \
5000 'brown', 15000 'black', 50000 'black')
splot 'line_01.dat' u 2:1:3:4 w p pt 1 palette, \
'line_03.dat' u 2:1:3:4 w p pt 1 palette, \
'line_04.dat' u 2:1:3:4 w p pt 1 palette
By default the palette maps the full range of Z values in the current plot. If you add/subtract/change the surfaces shown in the plot then the range of Z values may expand or contract, causing a change in the color mapped to a specific Z value.
You can prevent this by fixing the range of Z values used in the color mapping so that it is independent of the current plot content. For example
set cbrange [0:1000]
Will map the current palette onto Z values in the range 0 - 1000. Pixels with Z values outside this range will receive the max or min extreme color.
I was trying to plot number of particles in a square lattice. and I need each one to be coloured different. So I tried using palette.. by picking some random numbers but it always gives me black rectangles.. what should I do?
set obj rect from 1,5 to 2,6 fc palette 0.454545 → this is what is not working for me.
This is the image with all same color. I need different colour for each particle:
Plot using the boxxyerror style, and fill the boxes:
set size ratio -1
set style fill solid
plot 'file.dat' using 1:2:(0.1):(0.1):3 linecolor palette with boxxyerror
This would plot a square of size 0.2 at each position given by the first and second columns. The color is taken from the third column and mapped to the current palette. You must adapt that to your actual data format.
Working example using random pseudo-data ('+'):
set xrange [-0.05:1.05]
f = "int(rand(0) * 20)/20.0"
set style fill solid
set size ratio -1
plot '+' using (#f):(#f):(0.025):(0.025):(#f) linecolor palette notitle with boxxyerror
see What I gotI could get this working,what I did is initially set the pallette by the commands like "set palette model RGB defined ( 0 'green', 1 'blue', 2 'red', 3 'orange' )" ,"set palette model HSV defined ( 0 0 1 1, 1 1 1 1 )"(I got these from here-http://gnuplot.sourceforge.net/demo/pm3dcolors.html). Then I set rectangles as "set obj rect from x1,y1 to x2,y2 fc palette frac 0.57" . But I could see that there were some gaps between the squares and I could understand that it was because of problem with border so I added this "fs border palette frac 0.57",same colour. Even after doing these It wouldn't come out by the simple command "plot 0". So I had to modify it as "plot 0 lc palette frac 0.24 " (0.57 / 0.24 I just meant as example.. as you know it would be anything between 0 and 1). Now to remove the colorbox I used "unset colorbox". But why I had to write "plot 0 lc palette frac 0.24 " ?, to wakeup the palette? ,Is there any other way to show out the rectangles that we have already set without using a plot command ?
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 am making palette in gnuplot using commands:
set pm3d implicit at b
set palette model RGB maxcolors 5
set cbrange [0:20]
set palette model RGB defined (4 '#006400', 8 '#00008B', 12 'blue', 16 '#C71585', 20 'red')
set cbtics 4
This way I get order 20,16,12,8,4,0 from top to bottom on my vertical palette.
I need 0,4,8,12,16,20 reading from top to bottom.
I did not find any example already existing with this order (from smallest to biggest).
Thank you for your suggestions:)
hm, there seems not to be an easy way to to this. One solution would be to redefine the colorbar-tics
set cbtics ("20" 0,"16" 4,"12" 8,"8" 12,"4" 16,"0" 20)
and now you splot 20 minus the normal data. Then the colors should be again correct.