Managing the palette indicators in gnuplot - colors

I would like to ask if someone knows how to manage the palette indicators in gnuplot, I want it to fit with my colors(12) and not to be added automatically
my code is
set palette model HSV
set palette rgb 3,2,2
set palette maxcolors 12
set view map
set size square
set key off
set title "Neural network output (fitted curve)"
set xlabel "x"
set ylabel "y"
set zlabel "z"
set xrange [ -7.6625930750000002 : 27.166801390000000 ]
set yrange [ 0.35422432799999998 : 30.163194489999999 ]
set zrange [ -55.934824620000001 : 2.4059901000000002E-002 ]
set grid
set terminal png size 1200,900
set output "output/fitted_curve.png "
splot "output/plot_data_pl.txt " with points palette pt 7 ps 1

For the maximum flexibility, you should define your own palette.
Here is what I once did to obtain a plot with 7 distinct colors. Thereby, I can also define which color represents a given range of values.
set palette defined (0 "black",\
0.5 "black",\
0.5 "red",\
1.5 "red",\
1.5 "orange-red",\
2.5 "orange-red",\
2.5 "orange",\
3.5 "orange",\
3.5 "yellow",\
4.5 "yellow",\
4.5 "light-green",\
5.5 "light-green",\
5.5 "green",\
6.5 "green")
Hence, you actually have to define from / to which value you want a color to span.
Of course, you can use rgb definitions for your color. A list of gnuplot-defined colors is here.
For the sake of completeness, here is the entire code I used:
set view map
set pm3d
set term pngcairo crop font 'lmroman10,32' size 1152,864
set border lw 2
set palette defined (0 "black", 0.5 "black", 0.5001 "red", 1.5 "red", 1.5001 "orange-red", 2.5 "orange-red", 2.5001 "orange", 3.5 "orange", 3.5001 "yellow", 4.5 "yellow", 4.5001 "light-green", 5.5 "light-green", 5.5001 "green", 6.5 "green")
set xlab 'time step ' offset 0,1
set xtics 2500 offset 0,0.65
set ylab 'position [cell]' offset +.5,0
set cblab 'velocity [cells/(time step)]' offset -.8,0
set cbtics offset -1.2,0
set xrange[100000:110000]
set yrange[0:10000]
set cbrange[0:6.5]
set style line 1 lt 1 lc rgb "blue" lw .85 pt 6 ps .6
splot '6.csv' u (($1)):($2):($3) w p palette t '', 'data.csv' u (($1)):($2):($3*0) w l ls 1 t '', 'data2.csv' u (($1)):($2):($3*0) w l ls 1 t ''

Related

Show error bars in a multiaxis plot in Gnuplot

I have a dataset (show-errorbar.dat) containing:
Model# DE IE Error
Apple -4.6 -128.9538 4.0
Huawei -5.2 -176.6343 5.3
One-Pro -5.2 -118.1106 3.2
#!/usr/bin/gnuplot
#set terminal pdfcairo enhanced color font 'Helvetica,12' linewidth 0.8
set terminal png
set output 'BrandError.png'
set boxwidth 1.0 relative
set bmargin 5
set style fill solid border -1
set xtic rotate by -45 scale 0
#set auto x
set style line 81 lt 0 lc rgb "#808080" lw 0.5
set grid xtics
set grid ytics
set grid mxtics
set grid mytics
set grid back ls 81
set arrow from graph 0,first -4.6 to graph 1, first -4.6 nohead lw 2 lc rgb "#000000" front
set border 11
set border lw 2.0
set xtics font ",11"
set ytics font ",14"
set tics out
set ytics nomirror
set y2tics
set y2tics font ",14"
set mxtics 10
set mytics 2
set my2tics 2
set yrange [-10:0]
set y2range [-260:0]
set key left bottom
set y2label offset -2
set ylabel offset 2
set ylabel 'DE' tc rgb "red"
set y2label 'IE' tc rgb "green"
set style data histograms
set style histogram cluster gap 2
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'
plot 'show-errorbars.dat' using 2 ti 'DE' lc 2 axis x1y1, '' u 3:xticlabels(1) ti 'IE' lc 4 axis x1y2
set output
enter image description here
I would like to plot a histogram comparing DE vs IE and also show error bars (data in column 4) for the IE values.
Please any help on how to go about it.
There is a variant histogram style for exactly that purpose
set style histogram errorbars gap 2 {lw W}.
Here is the help section from the docs:
The `errorbars` style is very similar to the `clustered` style, except that it
requires additional columns of input for each entry. The first column holds
the height (y value) of that box, exactly as for the `clustered` style.
2 columns: y yerr bar extends from y-yerr to y+err
3 columns: y ymin ymax bar extends from ymin to ymax
The appearance of the error bars is controlled by the current value of
`set errorbars` and by the optional <linewidth> specification.
Updated answer
Notes:
You can't mix axis choice within a single histogram. So I have removed the axes x1y1 and axes x1y2 from the plot command. Since you have explicitly given the range for both y1 and y2, the plot border and labels are not affected.
However since the green bars are now being plotted against y1, we have to scale them so that the y2 axis labels apply. So the column 3 and column 4 values will be divided by 26, which is (y2 range) / (y1 range)
In "histogram errorbars" mode each plot component looks for an extra column of data to determine the size of the errorbar. Since your column 2 data has no corresponding column of errors, we dummy it up to use all a constant not-a-number (no data) value: (NaN)
Your data contains a line of columnheaders, which could confuse the program if it thinks this is a line of data. There are a number of ways you can tell the program to skip this line; I have used set key autotitle columnhead for convenience and because it is supported by old versions of gnuplot. If you have a current version it would be better to use instead set datafile columnheaders.
I have kept all of your commands except that the plot command is replaced by the following 3 lines:
set style histogram errorbars gap 2 lw 1.5
set key autotitle columnhead
plot 'show-errorbars.dat' using 2:(NaN) ti 'DE' lc 2, '' u ($3/26.):($4/26.):xticlabels(1) ti 'IE' lc 4

How to use color palette indexes for gnuplot box charts?

I try to map some index to a color of a defined palette. But the defined palette does not seem to get used.
Given a files data.txt:
11
22
33
44
The gnuplot commands:
set nokey
set grid
set style fill solid
set boxwidth 0.5
set yrange [0:]
set palette model RGB maxcolors 7
set palette defined (0 'dark-violet', 1 'skyblue', 2 'dark-yellow', 3 'dark-green', 4 'dark-red', 5 'coral', 6 'green', 7 'purple')
plot 'data.txt' using 0:1:(column(0)+1) with boxes linecolor variable
This gives:
This does not match the defined palette. How can I make gnuplot use the defined palette here with the index and color names?
This is the solution I came up:
set nokey
set grid
set style fill solid
set yrange [0:]
set palette defined (0 'dark-violet', 1 'skyblue', 2 'dark-yellow', 3 'dark-green', 4 'dark-red', 5 'coral', 6 'green', 7 'purple')
set cbrange [0 : 7]
unset colorbox
plot 'data.txt' using 0:1:(0.5):(column(0)) with boxes linecolor palette
The solution was to add the box width (0.5) in the plot row and to use cbrange and linecolor palette:

gnuplot map with pm3d, isolines and labels

In Gnuplot 5.0.1, I've tried without success to plot a map (with pm3d), including isolines and labels with numerical value of each isoline. It seems that I can obtain only isoline OR labels with isovalues.
set terminal qt font ",14"
unset surface
set title "OASPL [dB]" font ",18"
se xra[-15.401199999999999:14.497400000000001]
set xlabel "x [m]" font ",18"
set ylabel "y [m]" font ",18"
set cbrange[85:115]
set cbtics 85,3,115
set style data pm3d
set style function pm3d
set pm3d implicit at b
set palette negative grey maxcolor 10
set view map scale 1
set pm3d interpolate 10,10
set contour base
set cntrlabel onecolor format '%8.3g' font ',6' start 80 interval 20
set cntrparam levels increment 85,3,115
set style fill solid 1.00 border lt -1
set style textbox opaque margins 1.0, 1.0 border
spl 'OASPL-tec-carpet_03b180.dat' u 1:2:4 w l lw 1.3 lt -1 t ''
repl 'OASPL-tec-carpet_03b180.dat' u 1:2:4 w labels t ''
what I obtain is this (after the 'spl....')
or this (after the 'repl...')
There is a way to obtain both lines and labels?
Data file
I'm not sure ,but you can test this command:
spl 'OASPL-tec-carpet_03b180.dat' u 1:2:4 w l lw 1.3 lt -1 t '',
'OASPL-tec-carpet_03b180.dat' u 1:2:4 w labels t ''

Unique key and same size of graphs using multiplots [duplicate]

This question already has answers here:
Place key below multiplot graph in gnuplot
(2 answers)
Closed 8 years ago.
I want to put this two graphs together and I would like to use only one key. If I set one with notitle I could get them with only key, however the shape of the graphs will change.
set term postscript eps
set output "temp.eps"
set multiplot layout 1,2
set xtics ("32" 0, "128" 2, "512" 4, "2048" 6, "8192" 8)
#set grid ytics
set xrange [0:8]
set yrange [0:100]
p "8" u ($0):($6) w lp ps 0.75 notitle, "10" u ($0):($6) w lp lc rgb "#228B22" ps 0.75 notitle, "12" u ($0):($6)w lp lc rgb "black" ps 0.75 notitle , "14" u ($0):($6)w lp lc rgb "blue" ps 0.75 notitle, "16" u ($0):($6) w lp lc rgb "#D2691E" ps 0.75 notitle, "18" u ($0):($6)w lp lc rgb "#8A2BE2" ps 0.75 notitle, "20" u ($0):($6) w lp lc rgb "#20B2AA" ps 0.75 notitle
set xtics ("32" 0, "128" 2, "512" 4, "2048" 6, "8192" 8)
#set grid ytics
set xrange [0:8]
set yrange [0:100]
set xlabel "nel"
#set key location
set key invert
set key reverse
set key center right
set key outside
p "8" u ($0):($6) w lp ps 0.75 title "8", "10" u ($0):($6) w lp lc rgb "#228B22" ps 0.75 title "10", "12" u ($0):($6)w lp lc rgb "black" ps 0.75 title "12", "14" u ($0):($6)w lp lc rgb "blue" ps 0.75 title "14", "16" u ($0):($6) w lp lc rgb "#D2691E" ps 0.75 title "16", "18" u ($0):($6)w lp lc rgb "#8A2BE2" ps 0.75 title "18", "20" u ($0):($6) w lp lc rgb "#20B2AA" ps 0.75 title "20"
unset multiplot
This would produce something like:
As it can be seen, the shape of one graph would change due to the legend on its right. I looking for a way of using only legend and both figures using the shape of the graph on the left.
This question has two parts which I will address separately.
1) Can I use the same key for multiple plots?
No, unless the key would happen to be the same for the data in both plots anyway. For example, two plots with two lines each where the two lines would have the titles 'one' and 'two' in both plots could share the same key; two plots with one line each with the titles 'one' and 'two' in the separate plots could not share the same key.
2) How do I get my multiplots to be the same size when I have a key?
There is no easy way to do this, either you manually adjust the sizes of the plots, or you set up functions like in this answer.
In your case, it could look something like:
#!/usr/bin/env gnuplot
### n: change this parameter to equal the number of data sets to be plotted
n = 2
# l: left margin in pixels
l = 75.0
# k: key height in pixels (right margin)
k = 150.0
# m: margin between plots
m = 40.0
# p: plot width
p = 300.0
# w: width of output in pixels
w = p*n + m*(n-1) + l + k
### functions to help set top/bottom margins
lft(i,n,w,l,k) = (l+(w-l-k)*(i-1)/n)/w
rgt(i,n,w,l,k) = (l+(w-l-k)*i/n - m)/w
### first set up some basic plot parameters
set term pngcairo enhanced size w,600
set output 'multikey.png'
set ylabel 'Y Axis'
set xlabel 'X Axis'
set multiplot layout 1,(n+1) title 'Main title'
### First plot
# change only plot command here
currentplot = 1
set lmargin at screen lft(currentplot,n,w,l,k)
set rmargin at screen rgt(currentplot,n,w,l,k)
unset key
plot sin(1*x) notitle, \
sin(2*x) notitle
unset ylabel
### Middle data plot (commented out for this example)
# copy and paste this code to make more middle plots
#currentplot = currentplot + 1
#set lmargin at screen lft(currentplot,n,w,l,k)
#set rmargin at screen rgt(currentplot,n,w,l,k)
#unset title
#replot
### Last data plot
# change only plot command here
currentplot = currentplot + 1
set lmargin at screen lft(currentplot,n,w,l,k)
set rmargin at screen rgt(currentplot,n,w,l,k)
set xtics
replot
### Key plot
set lmargin at screen rgt(n,n,w,l,k)
set rmargin at screen 1
set key center center
set border 0
unset tics
unset xlabel
unset ylabel
set yrange [0:1]
plot 2 t 'Line 1', \
2 t 'Line 2'
unset multiplot
The result looks like this:
Note that I just provided example code. You might need to change it to get a proper plot.
You can set the size of the individual plots in multiplot using the following example: (It is an example , you might have to work with to get a correct size for your plots.)
set size 0.8,1.2
Try setting it for each of the individual plots.
You can set the overall size by
set terminal postscript enhanced eps 24 color size 10cm,15cm

How to plot discrete data on the cross-section of 3D graph in Gnuplot

I want to plot discrete data written in stp199inf2.dat on the cross-section at z=0, where functions c1 and c2 are also drawn.
I really need help now.
set multiplot
c1(x,y) = x**2 + y**2 -1 - 0.1*cos(16*atan(x/y))
c2(x,y) = (x-0.5)**2 + (y-0.5)**2 -0.5
C=0.7
set xrange[0:1.2]
set yrange[0:1.2]
set tics font"Times New Roman,12"
set xlabel "f1"
set ylabel "f2"
set xlabel font "Times New Roman, 12"
set ylabel font "Times New Roman, 12"
set key font "Times New Roman, 12"
set key right top
set isosamples 300,300
set contour base
set cntrparam levels discrete 0.0
set nosurface
set size square
set view 0,0,
splot c1(x,y) lt -1 lw 1 title ""
splot c2(x,y) lt -1 lw 1 title ""
splot c1(x,y) lt 3 lw 2.5 title "True Pareto Front"
splot './gnuplot_plot/stp199inf2.dat' lt 4 ps 3 pt 7
pause -1
-------------------stp199inf2.dat----------------------
1.037663 0.042694 0.0
0.071479 1.018838 0.0
0.871717 0.475405 0.0
0.909571 0.456881 0.0
0.996505 0.096337 0.0
With the unset surface also the points aren't drawn. So you must set the surface before plotting the points.
Some other remarks to your code:
If you have everything in a single plot you should use a single splot command with comma-delimited calls.
In that case you must unset the surface for the first three plot with the option nosurface.
You must unset the contours for the point plot with the option nocontour.
If you use set view map instead of set view 0,0, the overlapping zticlabels aren' drawn.
So, a reasonable script could look like:
set termoption font"Times New Roman,12"
set multiplot
c1(x,y) = x**2 + y**2 -1 - 0.1*cos(16*atan(x/y))
c2(x,y) = (x-0.5)**2 + (y-0.5)**2 -0.5
C=0.7
set xrange[0:1.2]
set yrange[0:1.2]
set xlabel "f1"
set ylabel "f2"
set key outside
set isosamples 300,300
set contour base
set cntrparam levels discrete 0.0
set size square
set view map
splot c1(x,y) lt -1 lw 1 title "" nosurface,\
c2(x,y) lt -1 lw 1 title "" nosurface,\
c1(x,y) lt 3 lw 2.5 title "True Pareto Front" nosurface,\
'stp199inf2.dat' lt 4 ps 3 pt 7 nocontour title ""
unset multiplot
The output with 4.6.3 is:
I'm not sure, how to best handle the contour key entries. I'll update the answer when I find something.

Resources