Gnuplot palette setting scale values - gnuplot

I have the following code:
unset key
set autoscale
set logscale x
# yellow red darkred
set palette model RGB defined ( 1 '#FFFF00', 12 '#FF0000', 13 '#8B0000' )
set terminal epslatex
set size 1.25,0.75
set cbrange [1:13]
set output "figs/plot.tex"
plot 'data/d1.csv' using 1:($2**2):(10*$3/m):3 with points pt 7 ps variable palette, \
'data/d2.csv' using 1:($2**2) with points pt 2 ps 2 lc 'black' lw 5
The ticks on the palette on the side of the plot go form 2 to 12 but I want it to go from 1 to 13 (so that both the min and max are marked). The data min=1 and max=12.5. How can I accomplish this?

If you want to add 1 and 13 as additional tics, you can use
set cbtics add (1, 13)
For tics at 1, 3, 5, 7, 9, 11, 13 use
set cbtics 1,3

Related

Absolute Palette in GnuPlot

What I'm doing is scatterplotting the atoms in molecules. Different colors for different elements with the palette defined just like above, but if I don't have one of those elements in the molecule, Gnuplot just rescales the whole color scheme and the molecule looks like crap.
Is there a way I can nail down 1 to be a color, 2 to be a color, 3 to be a color etc., without having to redefine the cbrange or palette for every molecule I plot? In other words, whether or not any one of those integers exist in the plot or not.
Set maxcolors to the number of different atoms. Specify the colors with set palette defined. Avoid rescaling by setting cbrange.
The following script has colors for atom types 1 to 6, but the data contains only atom types 1 to 4 which are displayed correctly:
set palette maxcolors 6
set palette defined (1 "#ff0000", 2 "#00ff00", 3 "#0000ff", \
4 "#ffff00", 5 "#00ffff", 6 "#ff00ff" )
set cbrange [0.5:6.5]
set xrange [0:5]
set yrange [0:2]
plot "-" notitle ls 5 ps 3 lc palette
1 1 1
2 1 2
3 1 3
4 1 4
The colorbox can be removed with unset colorbox.
Use linecolor variable to use a value from the data file as linetype:
set linetype 1 lc rgb "#ff0000"
set linetype 2 lc rgb "#00ff00"
set linetype 3 lc rgb "#0000ff"
$data << EOD
1 3 1
2 2 2
3 1 3
EOD
plot $data using 1:2:3 linecolor variable
Setting maxcolors did the trick. Thanks for looking out even when I forgot to post the code!

Error with graphics gnuplot

I'm programming a graph with axes (y "%" and x "date") and when less than 7 records have not shown well
These are the files
data.csv:
20-04-2016 96.8 95.8 100
21-04-2016 97.07 97.99 100
22-04-2016 98.05 99.5 100
23-04-2016 98.64 97.88 100
24-04-2016 98.96 98.99 100
25-04-2016 98.68 98.11 100
graph
reset
set terminal png size 1200,500
#set xlabel "Time (days)"
set xdata time
set timefmt "%d-%m-%Y"
set ylabel "Total Petitions (%)"
set yrange [95:100]
set title "Akamai"
set key reverse Left outside
set grid
set style data linespoints
plot "datos.csv" using 1:2 title "One (%)", \
"" using 1:3 title "Two (%)", \
"" using 1:4 title "Ideal (%)"
He shows me this
As shown, the dates are repeated, and I want one date per record appears.
I also like to put the date
%d-%m\n%Y
This is solved if I put 7 or more records
And this happens if I put the full date but the description of the axis x
It could put the date vertically?
Thank you very much for your help
Use set format x;
set terminal pngcairo enhanced color dashed \
rounded size 1200,500
set title "Akamai"
set xlabel "date"
set xdata time
set timefmt "%d-%m-%Y"
set format x "%d/%m\n%Y"
set xtics 86400
set nomxtics
set ylabel "Total Petitions (%)"
set yrange [95:100]
set style data linespoints
set grid
set key right bottom
set output 'user1847844.png'
plot "datos.csv" using 1:2 title "One (%)", \
"" using 1:3 title "Two (%)", \
"" using 1:4 title "Ideal (%)"
Internally, gnuplot converts datetimes to seconds. So the line set xtics 86400 basically says to make one tick per day since one day has 24*60*60 = 86400 seconds. The set nomxtics tells gnuplot to not show minor tick marks on the x-axis.
This gives:
If you want to rotate the label, use:
set format x "%d/%m/%Y"
set xtics rotate 86400
That should format the dates as a single line and rotate the labels by 90 degrees.
Update:
Note that I'm using the pngcairo terminal. This is based on the cairo graphics library. This is designed to give consistent output on all output media. But gnuplot must be compiled with cairo support for this to work.
In general, I prefer the pdfcairo terminal. This produces PDF output which can be scaled without giving pixellation effects.
Update 2:
To get consistency in my graphs, I've defined certain styles in my gnuplotrc, which I use in my graphs. The contents of my gnuplotrc are shown below.
set encoding utf8
# See https://github.com/Gnuplotting/gnuplot-palettes
# Line styles (colorbrewer Set1)
set style line 1 lc rgb '#E41A1C' pt 1 ps 1 lt 1 lw 2 # red
set style line 2 lc rgb '#377EB8' pt 6 ps 1 lt 1 lw 2 # blue
set style line 3 lc rgb '#4DAF4A' pt 2 ps 1 lt 1 lw 2 # green
set style line 4 lc rgb '#984EA3' pt 3 ps 1 lt 1 lw 2 # purple
set style line 5 lc rgb '#FF7F00' pt 4 ps 1 lt 1 lw 2 # orange
set style line 6 lc rgb '#FFFF33' pt 5 ps 1 lt 1 lw 2 # yellow
set style line 7 lc rgb '#A65628' pt 7 ps 1 lt 1 lw 2 # brown
set style line 8 lc rgb '#F781BF' pt 8 ps 1 lt 1 lw 2 # pink
# Palette
set palette maxcolors 8
set palette defined ( 0 '#E41A1C', 1 '#377EB8', 2 '#4DAF4A', 3 '#984EA3',\
4 '#FF7F00', 5 '#FFFF33', 6 '#A65628', 7 '#F781BF' )
# Standard border
set style line 11 lc rgb '#808080' lt 1 lw 3
set border 0 back ls 11
set tics out nomirror
# Standard grid
set style line 12 lc rgb '#808080' lt 0 lw 1
set grid back ls 12
unset grid
And I use a pdfcairo terminal as standard, like this.
set terminal pdfcairo enhanced color dashed font "Alegreya, 14" \
rounded size 16 cm, 9.6 cm
The font used is an example. For graphs in reports I tend to use the same font as the body text.
The plot command uses the defined styles.
plot "user1847844.d" using 1:2 ls 1 title "One (%)", \
"" using 1:3 ls 2 title "Two (%)", \
"" using 1:4 ls 3 title "Ideal (%)"
This produces a figure looking like this.
Note: Since StackOverflow doesn't accept PDF images, I converted it to a PNG using ImageMagick.
convert -density 300 <input.pdf> -quality 100 -sharpen 0x1.0 <output.png>

How to use "var" and "palette" together in gnuplot?

gnuplot script:
set xrange [25:60]
set yrange [45:80]
set palette defined(1 "red", 2 "green", 3 "blue")
unset key
unset colorbox
plot 'test.data' using 1:2:3:4 with points pt 7 ps var lt palette
test.data
x y count color
30 50 4 1
35 55 3 1
40 60 2 2
45 65 5 2
50 70 4 3
55 75 2 3
output:
I need so:
How to use "var" and "palette" together in gnuplot?
gnuplot Version 4.4 patchlevel 3
Seems like the autoscaling of the color range doesn't work properly in this case with version 4.4.3 (with 4.6.5 your script works out of the box). Also using set autoscale cbfix doesn't works as it seems to use the values of the third column for the scaling. (comment out unset colorbox to see this).
If you explicitely set a color range, it works fine also with 4.4.3:
set xrange [25:60]
set yrange [45:80]
set cbrange [1:3]
set palette defined(1 "red", 2 "green", 3 "blue")
unset key
unset colorbox
plot 'test.data' using 1:2:3:4 with points pt 7 ps var lt palette

How to remove palette colors heatmap

Is possible if heatmap palette(small rectangle on the right) to be removed?
this is my data
a b c
1 181 80 121 10 34 20
2 18 20 17 20 13 20
3 12 20 5 30 20 20
this is my gnuplot script
set term pos eps font 20
unset key
set nocbtics
set palette rgbformulae -7, 2, -7
set title "Faults"
set size 1, 0.5
set output 'heatmap2.eps'
YTICS="`awk 'BEGIN{getline}{printf "%s ",$1}' 'data2.dat'`"
XTICS="`head -1 'data2.dat'`"
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) i-1 )
set for [i=1:words(YTICS)] ytics ( word(YTICS,i) i-1 )
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) 2*i-1 )
plot "<awk '{$1=\"\"}1' 'data2.dat' | sed '1 d'" matrix every 2::1 w image, \
'' matrix using ($1+1):2:(sprintf('%d', $3)) every 2 with labels
I want to remove the palette because I adjust the ploting colors by percentage of my data. So, I guess the palette on the right my table is now use anymore. Thanks
That is the colorbox. Just use
unset colorbox
to remove it.

Show Y Label in groups with Gnuplot

I have this points:
0.00049 1.509
0.00098 1.510
0.00195 1.511
0.00293 1.509
0.00391 1.510
0.00586 1.523
0.00781 1.512
0.01172 1.514
0.01562 1.510
0.02344 1.511
0.03125 1.510
0.04688 7.053
0.06250 7.054
0.09375 7.187
0.125 7.184
0.1875 7.177
0.25 7.207
0.375 16.588
0.5 24.930
0.75 39.394
1 56.615
1.5 77.308
2 84.909
3 89.056
4 88.485
6 88.678
8 89.022
12 88.513
16 88.369
24 88.512
32 88.536
48 87.792
64 87.716
96 87.589
128 87.608
192 87.457
256 87.388
And this gnuplot script:
#! /usr/bin/gnuplot
set terminal png
set output "lat_mem_rd.png"
set title "Memory Latency Benchmark (Stride 512)"
set xlabel "Memory Depth (MB)"
set ylabel "Latency (ns)"
set xtics rotate by 45 offset 0,-1
set xtics font "Times-Roman, 8"
set grid
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1 # --- blue
plot "lat_mem_rd.dat" using (log($1)):2:xtic(1) smooth unique title "" with linespoints ls 1
which generates this graphic:
But i want to show the y values in the y label with one of the approximated values in those approximations, for example, for all of the values with x values between 3 and 256, the y label is set to just one, maybe 88.513 that corresponds to x=12 or other (or maybe the average of those points if its not very difficult)...
The same for x values between 0 and 0.02344 and for x values between 0.03125 and 0.1875.
This y values will substitute the values 10, 20, ..., 90.
Here is a modification of your script that might do what you want, if I understand you correctly:
set title "Memory Latency Benchmark (Stride 512)"
set xlabel "Memory Depth (MB)"
set ylabel "Latency (ns)"
set xtics rotate by 45 offset 0,-1
set xtics font "Times-Roman, 8"
set grid
a = ""; p = 0; nn = 1; nt = 37; d = 4; s = 0
f(x) = (x>p+d || nn >= nt)?(nn=nn+1, p=x, a=a." ".sprintf("%5.2f", s/n), n=1, s=x):(nn=nn+1, p=x, s=s+x, n=n+1)
plot "lat_mem_rd.dat" using 1:(f($2)) # Just to set array "a"
set ytics 0,0,0
set yrange [0:90]
set for [aa in a] ytics add (aa aa)
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1 # --- blue
set terminal png
set output "lat_mem_rd.png"
plot "lat_mem_rd.dat" using (log($1)):2:xtic(1) smooth unique title "" with linespoints ls 1
This script produces this plot:
The strategy is to accumulate a sum of Y-values and calculate an average every time the Y-value increases by at least an amount d; these averages are stored in a string variable "a", which is looped over to set the ytic values before the final plot command. This way clusters of closely-spaced Y-values give rise to a ytic at their average value; I think that was what you wanted.

Resources