Absolute Palette in GnuPlot - 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!

Related

gnuplot: how to set the different fill and border colors for `with points`?

I would like to achieve a similar effect in gnuplot.
Here is what I tried:
unset key
set style line 11 lc rgb '#808080' lt 1
set border 3 ls 11
set tics nomirror
set grid
set style line 1 lc rgb '#808080' pt 9 ps 3
set style line 2 lc rgb '#808080' pt 20 ps 3
set style line 3 lc rgb '#BD3828' pt 7 ps 3
set yrange [4:9]
$data << EOD
5 5.1
5.3 6.8
6 6
EOD
$data2 << EOD
5 5
7 7
8 6
EOD
$data3 << EOD
5.5 7
6 6
7 7.1
EOD
plot $data u 1:2 w points ls 1, $data2 u 1:2 w points ls 2, \
$data3 u 1:2 w points ls 3
As we can see, points can be overlapped. Then how can we darken the overlap areas?
A possible solution is to set transparency (e.g., lc rgb '#80808080'), but it will also make both border and filling transparent. So how to set the different fill and border colors for with points?
Another solution is to use set object, but we need to do more work to read data from files.
I think the closest you could come to what you describe is to draw the points in two passes.
First pass: draw using a point type that produces only the outlines (point types N = 4 6 8 10 12 ...).
Second pass: draw using the corresponding point type N+1 that produces only the interior, using the same color but adding an alpha channel value to make it partially transparent.
set print $RAND1
do for [i = 1:50] { print rand(0), rand(0) }
unset print
set print $RAND2
do for [i = 1:50] { print rand(0), rand(0) }
unset print
set pointsize 4
plot $RAND1 with points pt 8 lc rgb "#00b8860b", \
'' with points pt 9 lc rgb "#AAb8860b", \
$RAND2 with points pt 6 lc rgb "#00c04000", \
'' with points pt 7 lc rgb "#AAc04000"

How to make gnuplot charts look more visually appealing?

I have been working with gnuplot for a while now. Recently started using it to create reports to send to customers. I tried to experiment with my plotting script but not much has come of it.
My question simply is, how to make charts from Gnuplot look really awesome? Think of D3/chartjs output for comparison.
I understand 'awesome' is subjective. But general pointers in this regard would help a lot!
Look for color palettes that you like online. One nice source is this.
Experiment with border styles, grid styles et cetera.
Once you are happy with it, put the style items in your gnuplotrc.
This is my gnuplotrc:
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 this is my template for gnuplot files:
set terminal pdfcairo enhanced color dashed font "Alegreya, 14" \
rounded size 16 cm, 9.6 cm
# Default encoding, line styles, pallette, border and grid are set in
# /usr/local/share/gnuplot/x.y/gnuplotrc.
set xlabel "x"
set ylabel "f(x)"
set grid
set key right top
set xrange[0:6.28]
set yrange[-1:1]
set output 'sinx.pdf'
plot sin(x) w l ls 1, cos(x) w l ls 2
(You should change the font to one that you have available.)
It looks like this:
Is this awesome? Well I like to think so! But in all seriousness, there are reasons for this layout.
I want the data to be paramount. That is why the border is not empasized and there is no background color.
Nevertheless, I want the viewer to see where the graph crosses the values shown on the labels, hence the visible tickmarks and (unobtrusive) grid.
To make the graphs "fit" into the style of the document I tend to do a couple of things:
Use the same font as the body text of my documents.
Use the same size, line style, borders et cetera for all the graphs in the document.
Match the graph size to the width of the column or text block.

Is there a way to prevent gnuplot from using solid points?

I am automatically generating .plt files for an unknown number of input files per graph. My problem is when gnuplot chooses solid shapes for the points (filled in square), the solid points overwhelm all the other types of points. In this image of gnuplot point types
is there a way for me to say do not use 5,7,11,13,etc? Or perhaps the inverse of this (use 1,2,3,4,6,8,etc...)?
You can use set linetype to select the point types which are used:
set linetype 1 pt 1
set linetype 2 pt 2
set linetype 3 pt 3
set linetype 4 pt 4
set linetype 5 pt 6
set linetype 6 pt 8
set linetype 7 pt 10
set linetype 8 pt 12
set samples 11
plot for [i=1:8] i*x with points notitle

values at x-axis fall in between xtics

I am trying to plot a graph where the x-values fall in between xtics.
For example, I want my xtics to be
C72 C73 C74 C75 C76 C77 C78 C79 C80 C81
and the points fall in between C72 C73 ; C73 C74 ; C74 C75 ; and so on.
My data points are
> 2.5 0.17509 C72
> 3.5 0.220434 C73
> 4.5 0.164918 C74
> 5.5 0.172477 C75
> 6.5 0.156145 C76
> 7.5 0.171699 C77
> 8.5 0.165199 C78
> 9.5 0.191207 C79
> 10.5 0.211656 C80
> 11.5 0.202233 C81
I used xticlabels() in the script definitions as below:
#OUTPUT
set terminal pngcairo size 650,450 enhanced dash
set output "xplot_gauche_malto-thermo.png"
set style line 4 lt 4 lw 10 # Please DISABLE pause -1
#MICRO
set macro
labelFONT="font 'arial,22'"
scaleFONT="font 'arial,18'"
scaleFONT2="font 'arial,18'"
keyFONT="font 'arial,18'"
# AXIS DEFINITIONS
set xrange [0:12]
set yrange [0:0.8]
set xtic (2,3,4,5,6,7,8,9,10,11) #scaleFONT2
set ytic #scaleFONT
set boxwidth 0.8
set size square
#PLOT
plot "all_dihedrals_in_layers_malto.dat" using 1:2:xticlabels(3) with linespoints lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title ""
If I use the code as above, to get a plot using only column 1 and 2 from data file (as given above) I get the points fall in between 2-3, 3-4, 4-5 and so on.
Unfortunately if I use "xticlabels()", I don't get the graph as I wanted where the point supposed to fall in between C72-C73, C73-C74, C74-C75 and so on.
Appreciate in advance for any help.
Thanks
try something like this.. (Untested i dont have gnuplot on this machine..)
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):0/0:xticlabels(3)
of course you could alternately manually key in the labels on the set xtics line..
Edit..had a chance toi try it, the 0/0 or (0/0) does not work. What you need to do is plot some value out of range.. eg:
set yrange [0:]
plot "all_dihedrals_in_layers_malto.dat" using 1:2 with linespoints \
lw 2 linecolor rgb "black" pointtype 1 pointsize 2 title "" ,\
"all_dihedrals_in_layers_malto.dat" using ($1-.5):-1:xticlabels(3) notitle

gnuplot png output doesn't plot dashed/dotted lines

I'm trying to plot a figure that contains both dashed and continuous lines with gnuplot v4.4 . The code is:
set term postscript eps enhanced color
set style line 1 linetype 1 lw 2
set style line 2 linetype 1 lw 2 linecolor rgb 'green'
set style line 3 linetype 1 lw 2 linecolor rgb 'blue'
set style line 4 linetype 4 lw 2 linecolor rgb 'red'
set style line 5 linetype 3 lw 2 linecolor rgb 'blue'
set border lw 3
set xtics font ',18'
set ytics font ',18'
set output 'roc.ps'
set key right bottom
plot 'roc_fpdock_isc_test' u 1:2 w l ls 1 title "Full optimization, test set" ,x w l ls 2 title "Random", 'roc_fpdock_isc_training' u 1:2 w l ls 3 title "Full optimization, training set", 'roc_mini_pep_sc_training' u 1:2 w l ls 4 title "Minimization only, training set", 'roc_mini_pep_sc_test' u 1:2 w l ls 5 title "Minimization only, test set"
Problem is , I can't plot it to png. When I change the set term instruction to: set term png enhanced I get only continuous lines.
Any idea what went wrong?
It turns out that I can't seem to get dashed lines in the png terminal either (the one with the GD backend). However, if you have the cairo terminals, you can get a png with dashed lines (assuming you pick the appropriate linetypes).
set term pngcairo dashed
set output "foo.png"
test
!display foo.png
!rm foo.png
As an aside, test is fantastic for inquiring what the behavior of a particular terminal will be.
You have the dt option for dashtype in pngcairo. Legend here:
e.g
set style line 5 linetype 3 dt 5 lw 3 linecolor rgb 'green'
gives dashtype 5

Resources