Can't use palette to fill object with colour - colors

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 ?

Related

Mapping between data and line color in gnuplot

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/

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

Add a single point at an existing plot

I am using the following script to fit a function on a plot. In the output plot I would like to add a single value with etiquette on the fitting curve lets say the point f(3.25). I have read that for gnuplot is very tricky to add one single point on a plot particularly when this plot is a fitting function plot.
Has someone has an idea how to add this single point on the existing plot?
set xlabel "1000/T (K^-^1)" font "Helvetica,20"
#set ylabel "-log(tau_c)" font "Helvetica,20"
set ylabel "-log{/Symbol t}_c (ns)" font "Helvetica,20"
set title "$system $type $method" font "Helvetica,24"
set xtics font "Helvetica Bold, 18"
set ytics font "Helvetica Bold, 18"
#set xrange[0:4]
set border linewidth 3
set xtic auto # set xtics automatically
set ytic auto # set ytics automatically
#set key on bottom box lw 3 width 8 height .5 spacing 4 font "Helvetica, 24"
set key box lw 3 width 4 height .5 spacing 4 font "Helvetica, 24"
set yrange[-5:]
set xrange[1.5:8]
f(x)=A+B*x/(1000-C*x)
A=1 ;B=-227 ; C=245
fit f(x) "$plot1" u (1000/\$1):(-log10(\$2)) via A,B,C
plot [1.5:8] f(x) ti "VFT" lw 4, "$plot1" u (1000/\$1):(-log10(\$2)) ti "$system $type" lw 10
#set key on bottom box lw 3 width 8 height .5 spacing 4 font "Helvetica, 24"
set terminal postscript eps color dl 2 lw 1 enhanced # font "Helvetica,20"
set output "KWW.eps"
replot
There are several possiblities to set a point/dot:
1. set object
If you have simple points, like a circle, circle wedge or a square, you can use set object, which must be define before the respective plot command:
set object circle at first -5,5 radius char 0.5 \
fillstyle empty border lc rgb '#aa1100' lw 2
set object circle at graph 0.5,0.9 radius char 1 arc [0:-90] \
fillcolor rgb 'red' fillstyle solid noborder
set object rectangle at screen 0.6, 0.2 size char 1, char 0.6 \
fillcolor rgb 'blue' fillstyle solid border lt 2 lw 2
plot x
To add a label, you need to use set label.
This may be cumbersome, but has the advantage that you can use different line and fill colors, and you can use different coordinate systems (first, graph, screen etc).
The result with 4.6.4 is:
2. Set an empty label with point option
The set label command has a point option, which can be used to set a point using the existing point types at a certain coordinate:
set label at xPos, yPos, zPos "" point pointtype 7 pointsize 2
3. plot with '+'
The last possibility is to use the special filename +, which generates a set of coordinates, which are then filtered, and plotted using the labels plotting style (or points if no label is requested:
f(x) = x**2
x1 = 2
set xrange[-5:5]
set style line 1 pointtype 7 linecolor rgb '#22aa22' pointsize 2
plot f(x), \
'+' using ($0 == 0 ? x1 : NaN):(f(x1)):(sprintf('f(%.1f)', x1)) \
with labels offset char 1,-0.2 left textcolor rgb 'blue' \
point linestyle 1 notitle
$0, or equivalently column(0), is the coordinate index. In the using statement only the first one is taken as valid, all other ones are skipped (using NaN).
Note, that using + requires setting a fixed xrange.
This has the advantages (or disadvantages?):
You can use the usual pointtype.
You can only use the axis values as coordinates (like first or second for the objects above).
It may become more difficult to place different point types.
It is more involved using different border and fill colors.
The result is:
Adding to Christoph's excellent answers :
4. use stdin to pipe in the one point
replot "-" using 1:(f($1))
2.0
e
and use the method in 3rd answer to label it.
5. bake a named datablock
(version > 5.0) that contains the one point, then you can replot without resupplying it every time:
$point << EOD
2.0
EOD
replot $point using 1:(f($1)):(sprintf("%.2f",f($1))) with labels
6. A solution using a dummy array of length one:
array point[1]
pl [-5:5] x**2, point us (2):(3) pt 7 lc 3
7. Or through a shell command (see help piped-data):
pl [-5:5] x**2, "<echo e" us (2):(3) pt 7 lc 3
pl [-5:5] x**2, "<echo 2 3" pt 7 lc 3
8. Special filename '+'
pl [-5:5] x**2, "+" us (2):(3) pt 7 lc 3
It seems to be the shortest solution. But note that while it looks like a single point, these are like 500 points (see show samples) plotted on the same position.
To have only one point the sampling needs to be temporarily adjusted (see help plot sampling)
pl [-5:5] x**2, [0:0:1] "+" us (2):(3) pt 7 lc 3
9. Function with zero sampling range length
Shortest to type, but plotting as many points on top of each other as many specified with samples
pl [-5:5] x**2, [2:2] 3 w p pt 7 lc 3

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")

Gnuplot change color of bars in histogram

is it possible to change the color of bars in a Gnuplot script dynamically?
I have the following script
reset
fontsize = 12
set term postscript enhanced eps fontsize
set output "bargraph_speedup.eps"
set style fill solid 1.00 border 0
set style histogram
set style data histogram
set xtics rotate by -45
set grid ytics linestyle 1
set xlabel "Benchmarks" font "bold"
set ylabel "Relative execution time vs. reference implementation" font "bold"
set datafile separator ","
plot 'bm_speedup.dat' using 2:xtic(1) ti "Speedup" linecolor rgb "#00FF00"
which generates this plot:
Is it possible to make the color of the bars which are below zero red?
Thanks,
Sven
You can mimic this behavior using the boxes style:
My test data:
zip 2
baz 2
bar -1
cat 4
foo -3
And then plotting with gnuplot:
set style line 1 lt 1 lc rgb "green"
set style line 2 lt 1 lc rgb "red"
set style fill solid
plot 'test.dat' u (column(0)):2:(0.5):($2>0?1:2):xtic(1) w boxes lc variable
# #xval:ydata:boxwidth:color_index:xtic_labels
You could split your data file into two parts, positive values and negative, and plot them separately:
plot 'bm_speedup_pos.dat' using 2:xtic(1) ti "Faster" linecolor rgb "#00FF00", \
'bm_speedup_neg.dat' using 2:xtic(1) ti "Slower" linecolor rgb "#FF0000"
Or, if you only need to generate a few graphs, a few times, a common technique is to generate the raw graph in gnuplot, then post-process it in an image editor to adjust the colors. If you go that route, I suggest having gnuplot generate the graph in SVG format, which will give you much better looking graphs than any of the bitmap formats.
Doesn't seem like histogram lets you do it. May be like this:
set boxwidth 0.3
f(v)=v<0?1:2
plot 'bm_speedup.dat' using 0:2:(f($2)):xticlabels(1) with boxes ti "Speedup" lc variable
Actually you can also use linecolor rgb variable and give the color like this:
plot 'bm_speedup.dat' using 2:xtic(1):($2 >= 0 ? 0x00FF00 : 0xFF0000) ti Speedup lc rgb variable

Resources