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

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

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 "filledcurves" change color when two or more meet? (GNUPlot)

I have created a graph that uses lines for the average of my data and filledcurves for the error (average-error, average+error). My problem is that the last filledcurves that is plotted, covers all other fills, even though I have set its transparency. I want to change this so that when two or more filledcurves meet the color is changed and thus the errors are clearly shown for all lines.
My script is:
set datafile separator whitespace
set style line 1 lc rgb '#aa5500' lt 1 lw 2 pt 7 ps 1
set style line 2 lc rgb '#55aaff' lt 1 lw 2 pt 7 ps 1
set style line 3 lc rgb '#aa557f' lt 1 lw 2 pt 7 ps 1
set style line 4 lc rgb '#55007f' lt 1 lw 2 pt 7 ps 1
set style line 5 lc rgb '#005500' lt 1 lw 2 pt 7 ps 1
set style line 6 lc rgb '#0055ff' lt 1 lw 2 pt 7 ps 1
set tics nomirror
set tics front
set style line 12 lc rgb '#808080' lt 0 lw 1
set grid front ls 12
set output 'network_utilization_servers_3_2.png'
set terminal png size 1000,800
set style fill transparent solid 0.25
set style fill noborder
set xrange[0:77]
set yrange[0:1500]
set xlabel "Time (seconds)" font ",12"
set ylabel "Incoming Traffic (KB/s)" font ",12"
set title "Network Utilization in the Servers" font "Helvetica,16"
set key box title "Server" width 10
plot for [i=0:|Group|-1] $Data3 u ($2-6):($3-$4):($3+$4) index i with filledcurves ls i+1 notitle, \
for [i=0:|Group|-1] $Data3 u ($2-6):3:4 index i w lines ti sprintf("%g",Group[i+1]) ls i+1
and my pragh:
My goal is something like this:
Is there a way to achieve this?

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.

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!

Set point size independent of line weight

I have the following line styles defined in gnuplot:
set linetype 1 lc rgb "red" lw 3 pt 7
set linetype 3 lc rgb "red" lw 1 pt 7
It appears as though the points derive part of their size from the lineweight. I'm using these styles inside of a plot for loop with linetype cycle using the same style for a cspline and the corresponding points, so I don't see any easy way to just define a separate style for the points.
I get results like this:
The points respond to pointsize but the point in linetype 1 is still slightly larger (presumably from the thicker border).
Is it possible to get the points in these two styles to be the same size?
In response to Miguel's comment, a more complete example of my use case is:
filenames = "A B C D"
set linetype 1 lc rgb "blue" lw 3 pt 7
set linetype 2 lc rgb "red" lw 3 pt 7
set linetype 3 lc rgb "blue" lw 1 pt 7
set linetype 4 lc rgb "red" lw 1 pt 7
set linetype cycle 4
plot for [file in filenames] file.".csv" \
using 1:2
title file \
smooth csplines, \
for [file in filenames] file.".csv" \
u 1:2 with points notitle
linetypes 5-8 get set by the cycling and are used by the last part of the plotting command. Recommendations on another way to do this would be welcome!
For your very specific case you can set more styles, and do it rather automatically with a do for loop (reusing your code):
filenames = "A B C D"
do for [i=0:1] {
set linetype (4*i+1) lc rgb "blue" lw (i == 1 ? 0 : 3) pt 7
set linetype (4*i+2) lc rgb "red" lw (i == 1 ? 0 : 3) pt 7
set linetype (4*i+3) lc rgb "blue" lw (i == 1 ? 0 : 1) pt 7
set linetype (4*i+4) lc rgb "red" lw (i == 1 ? 0 : 1) pt 7
}
set linetype cycle 8
plot for [file in filenames] file.".csv" \
using 1:2 \
title file \
smooth csplines, \
for [file in filenames] file.".csv" \
u 1:2 with points notitle
With some simple data files:
For some terminals the size of filled point types depends on the linewidth because they have a border. This is the case for all cairo-based terminals (pdfcairo, pngcairo, wxt and cairolatex), whereas other terminal like svg, postscript, qt don't show this behaviour.
As test case consider
set linetype 1 lc rgb "red" lw 3 pt 7
set linetype 3 lc rgb "red" lw 1 pt 7
set samples 11
set style function linespoints
plot x lt 1, x + 0.5 lt 3
Considering that you want to have the linepoints samples in the legend, you're best choice is to reduce the point size a bit for the line type with the larger linewidth, like
set linetype 1 lc rgb "red" lw 3 pt 7 ps 0.9
The choice of the scaling factor must be determined manually.

Resources