gnuplot palette changes color with zoom - gnuplot

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.

Related

Can't use palette to fill object with colour

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 ?

Add Error Bars to GNUPlot Barplot

I have a very simple chart like this
and I would like to add vertical error bars above and below the top of each bar.
my GNUPlot input is
set boxwidth 0.5
set style fill solid
set title 'title'
set key off
set ylabel 'ylabel'
set xtics font 'Arial, 24'
set ytics font 'Arial, 18'
set title font 'Arial, 24'
set ylabel font 'Arial, 16'
set terminal pngcairo size 1000,1000# gnuplot recommends setting terminal before output
set output 'pathfinder.png'
plot 'pathfinder.txt' every ::0::0 using 1:3:xtic(2) with boxes lc rgb 'red', \
'pathfinder.txt' every ::1::1 using 1:3:xtic(2) with boxes lc rgb 'green', \
'pathfinder.txt' every ::2::2 using 1:3:xtic(2) with boxes lc rgb 'blue', \
'pathfinder.txt' every ::3::3 using 1:3:xtic(2) with boxes lc rgb 'orange',
and my data
#x axis location, label, height of bar, low part of error bar, high part of error bar
0 A 209.3 200 219
1 B 4790.2 4700 4900
2 C 3771.2 3700 3900
3 D 170.3 150 200
I have seen similar posts, namely adding error bar to histogram in gnuplot and Adding error bars on a bar graph in gnuplot but I don't see how it applies with this case.
How can I modify my GNUPlot script to add error bars?
thanks so much!
The two links you mentioned basically contain the answer, however,
from you example it looks like you want filled bars with defined colors.
From help boxerrorbars:
The error bar will be drawn in the same color as the border of the
box.
So, you have several options:
(top left) "same color as the border of the box" of course doesn't make sense if you fill your bar, since the lower part of the error bar will disappear in the filled bar.
(top right) set the border e.g. "black", which will make the errorbar black as well
(bottom left) set the intensity of the solid fill, e.g. to 0.3, which will leave the border in intensity 1.0 and hence the errorbar as well.
(bottom right) split the plot in with boxes and with yerrorbars then your are completely independent for the colors. There is a point with the yerrorbar which you can let disappear by specifying ps 0 (or pointsize 0)
Script: (works with gnuplot>=5.0.0, Jan. 2015)
### filled bars with errorbars
reset session
$Data <<EOD
#x axis location, label, height of bar, low part of error bar, high part of error bar
0 A 25 17 33
1 B 50 40 60
2 C 85 71 91
3 D 40 33 47
EOD
set palette defined (1 "red", 2 "green", 3 "blue", 4 "orange")
unset colorbox
set key noautotitle
set yrange[0:100]
set grid y
set tics out
set offset 0.25,0.25,0,0
set multiplot layout 2,2
set style fill solid 1.0 noborder
plot $Data u 1:3:4:5:(0.5):0:xtic(2) w boxerrorbars lc palette
set style fill solid 1.0 border lc "black"
replot
set style fill solid 0.3 border
replot
set style fill solid 1.0
plot $Data u 1:3:(0.5):0:xtic(2) w boxes lc palette, \
'' u 1:3:4:5 w yerr pt 6 ps 1 lc "black"
unset multiplot
### end of script
Result:

gnuplot - filled curve with palette color

I'm trying to plot a histogram in gnuplot, where the bars are characterized by their color (intensity) instead of their height (frequency). To do so, I want to fill each bar with a color corresponding to the third column (which stands for this intensity) of a data file, defined in a palette. All the bars have the same height y=1 and the same width dx=1. The important part of the script looks like
plot for [ii=0:N] 'data.dat' index ii u 1:2:3 w filledcu y1=0 lc palette
My problem is that the ii=0 takes the right color of the palette and fills the first bar, but from there on all the others are the same color ( same intensity ) than ii=0.
My data file looks like:
X Y Intensity
1 1 0.6
2 1 0.6
...
Any idea to fill with the right color ?
The filledcurves plotting style doesn't support color gradients, see Gnuplot filledcurves with palette.
Since you have the same height for every bar, you can use the boxes plotting style:
set style fill solid noborder
plot 'data.dat' using 1:2:3 with boxes lc palette

Custom legend (or text) gnuplot

I have a file with 3 columns, the first 2 are the position x y and the 3rd one I use it for define the color so I have something like this:
set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red')
unset colorbox
plot "file" u 2:1:3 w points pt 14 ps 2 palette, "file2" u 2:1:3 w points pt 14 ps 2 palette
Now the question: Is it possible to have a proper legend with this kind of point and COLOR?.
Since the points will have different colors (according to the pallete) I want to specify what means each color in the legend.
The only solution I was thinking was to write somewhere in the plot some text with the character of the point (in this case pt 14) and specify the color... but is not really a solution right?
So please help!
There is no option for this, you need to fiddle a bit. Here is YAGH (Yet another gnuplot hack) ;)
Assuming that your values are equidistantly spaced, you can use the '+' special filename with the labels plotting style.
To show only the custom key, consider the following example:
labels="first second third fourth"
set xrange[0:1] # must be set for '+'
set yrange[0:1]
set samples words(labels) # number of colors to use
key_x = 0.8 # x-value of the points, must be given in units of the x-axis
key_y = 0.8
key_dy = 0.05
set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red')
unset colorbox
plot '+' using (key_x):(key_y + $0*key_dy):(word(labels, int($0+1))):0 \
with labels left offset 1,-0.1 point pt 7 palette t ''
This gives (with 4.6.4):
As the set samples doesn't affect the data plots, you can integrate this directly in your plot command:
...
unset key
plot "file" u 2:1:3 w points pt 14 ps 2 palette, \
"file2" u 2:1:3 w points pt 14 ps 2 palette, \
'+' using (key_x):(key_y - $0*key_dy):(word(labels, int($0+1))):0 \
with labels left offset 1,-0.1 point pt 14 ps 2 palette
But you need to set a proper xrange, yrange and the values of key_x, key_y and key_dy.
This is not the most intuitive way, but it works :)
I have an alternative solution posted here:
Using Gnuplot to plot point colors conditionally
Essentially you plot once without a legend entry, then make dummy plots (with no data) for each point color/label.

Symmetric axes in gnuplot

I want to draw a contour plot with gnuplot, where I want to point out some special features with special colors.
I define the contour plot by
set pm3d map
set palette defined (-1 "red", -0.1 "red", 0 "white", 0.1 "blue", 1 "blue")
This results in a color gradient which has a small area with a gradient from red to white to blue and the remaining part is red for negative numbers and blue for positive numbers.
My problem is now, that I would like to set gnuplot automatically to a symmetric scaling of the z-axis. But by specifying splot [][][-200:200] 'data' u 1:2:3 and a dataset with values from e.g. -300 to 100 gnuplot does an automatic rescale to [-200:100] which results in a misalignment of my colorscale (the white area is now around -50).
Is there a way to force a zrange or get an automatically symmetric scaled axis?
I'm not sure I understand the problem, but have you considered:
set cbrange [-200:200]
From the documentation:
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.
To force a z range, try
set zr [-200:200]
before your plot command. To automatically scale the axis you could probably cook something up using stats. The main trick is to keep in mind that the color bar is in relative units. Something like this (untested):
datafile = 'data.dat'
stats datafile u 3 nooutput
# assume you want some data positive and some negative
if (stats_max*stats_min > 0) {
print 'WARNING: all data has same sign. Color bars may be weird.'
}
z0 = -1*min(abs(0.1*stats_min),abs(0.1*stats_max))
z1 = 0.0
z2 = -1*z0
set palette defined (stats_min "red", z0 "red", z1 "white",
z2 "blue", stats_max "blue")

Resources