Can I put comments into long plot commands? - gnuplot

My gnuplot plot command is
tM=1.0*(a0*xmax+ymax)
set parametric
set trange [-0.2:tM]
plot 1/0,1/0 title '\ict\qquad' lc rgb 'gray80' dt 5 lw 2,\
uldx0(t),uldy0(t) title '\disct' lc rgb 'web-green' lw 3,\
hpx0(t),hpy0(t) lc rgb 'pink' lw 2,\
vpx0(t),vpy0(t) with filledcurve xy= 0.5*(xmi0+xpl0),0\
fs transparent solid 0.25 fc rgb 'cyan' ,\
for [n=1:5] ix0(n*0.05+t*n*0.005/tM ,u0(0,n*0.05)),\
iy0(n*0.05+t*n*0.005/tM,u0(0,n*0.05))\
lc rgb 'gray80' dt 5 lw 2,\
for [n=6:10] ix0(n*0.05+t*n*0.01/tM ,u0(0,n*0.05)),\
iy0(n*0.05+t*n*0.01/tM,u0(0,n*0.05))\
lc rgb 'gray80' dt 5 lw 2,\
for [n=22:36] ix0(n*0.025+t ,u0(0,n*0.025)),\
iy0(n*0.025+t,u0(0,n*0.025))\
lc rgb 'gray80' dt 5 lw 2,\
x0(t*pmax0(q1)/tM,q1), y0(t*pmax0(q1)/tM,q1) \
lc rgb q1color lw 2,\
x0(t*pmax0(ql0)/tM,ql0), y0(t*pmax0(ql0)/tM,ql0) \
lc rgb qlcolor lw 2,\
x0(t*pmax0(QqxyL0)/tM,QqxyL0), y0(t*pmax0(QqxyL0)/tM,QqxyL0) \
lc rgb qhatmicolor lw 2,\
x0(t*pmax0(q2)/tM,q2) , y0(t*pmax0(q2)/tM,q2) \
lc rgb q2color lw 2,\
x0(t*pmax0(qpl0)/tM,qpl0), y0(t*pmax0(qpl0)/tM,qpl0) \
lc rgb qplcolor lw 2,\
x0(t*pmax0(QqxyR0)/tM,QqxyR0), y0(t*pmax0(QqxyR0)/tM,QqxyR0) \
lc rgb qhatplcolor lw 2
Is there a good way to break this up with comments which would also help may should I decide to look at this later?

All inside a single plot command, right?
I think the closest is to take advantage of the fact that each clause of a plot command can start with a definition. The intended use is something like plot a=2 x**a, but you could pick some junk variable and assign it to a comment string
plot \
_c="Straight line" x title _c, \
_c="Parabola" x**2 title 'x^2', \
_c="Some weird function" real(sinh(sqrt(x))) title 'squint(x)'
If you like you can use that comment string in the plot title, which is something close to the originally intended use. But also you can just ignore it in the plot clause. It would then only be relevant to someone reading the source, not to the output from the plot command.

Related

gnuplot 5.5: no auto axis limits

I've installed gnuplot 5.5 from git. Now it doesn't plot with automatic axis limits.
Here is the graph produced with earlier version (5.3 or 5.4):
And this is plotted with current version:
Here is the command for this plot:
plot [][3.0145:3.5755] 3.04 w filledcurves x1 fc rgb "#d9d9d9" notitle, \
3.55 w filledcurves x2 fc rgb "#d9d9d9" notitle, \
for [i=1:11] 'gpdata.dat' every :::0::0 using 1:i+1 lt i+1 lw 3 ps 1.5 t word(elements,i) w linesp,\
3.04 w lines lw 4 lt 1 lc rgb "red" t 'Допуск',3.55 w lines lw 4 lt 1 lc rgb "red" notitle
When I set the limits explicitly: plot [:35064.46][3.0145:3.5755] I get this:
i.e. the end points are hidden.
Is there a way to return previous behavior?
According to the StackOverflow "rules": no answer in the comments...
set xrange[:] noextend
should avoid the extension of the plotting range to the next "nice" tic. Check help noextend.

Gnuplot line and key colors

I'm trying to use Gnuplot to create a line chart. Each line is represented by a different color. What I want is the key has the same color as the line color. This is what I have right now, current version. Is it possible to set the text 'Line 2' colored as orange, 'Line 3' colored as red, etc?
This is what I wrote in the gp file:
set xlabel'x-axis'; \
set xrange[0:25];\
set ylabel 'y-axis';\
set yrange [2:9];\
set key left top;
p 'test.dat' using 1:2 w linespoints lw 5 lc rgb '#aadc32' pt 17 title 'Line 1' ,\
'test.dat' using 1:9 w linespoints lw 5 lc 'orange' lt 1 title 'Line 2',\
'test.dat' using 1:6 w linespoints lw 5 lc 'red' lt 8 title 'Line 3',\
'test.dat' using 1:7 w linespoints lw 5 lc 'violet' pt 6 title 'Line 4',\'test.dat' using 1:8 w linespoints lw 5 lc rgb '#b5367a' pt 19 title 'Line 5',\
'test.dat' using 1:3 w linespoints lw 5 lc 'cyan' pt 9 title'Line 6',\
'test.dat' using 1:4 w linespoints lw 5 lc 'blue' lt 9 title 'Line 7',\
'test.dat' using 1:10 w linespoints lw 5 lc rgb '#1c1044' lt 5 title 'Line 8',\
Thank you so much.
Unfortunately not. The plot title does not (now, gp5.2pl0) recognise the "textcolor" specifier.
plot x lw 3 lc rgb "blue" title "x" tc rgb "blue" # doesn't work
You can only print an empty (" ") plot title, and overprint it with a coloured label
set label 1 at 8,1 "bluetitle" tc rgb "blue"
That requires some fiddling with the placement of the label, of course.
You might put up a feature request on https://sourceforge.net/p/gnuplot/feature-requests/

How to make key colour black in Gnuplot

How can I make the key "symbols" black in colour when using palettes?
I think you cannot control this directly, here a workaround:
plot 'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt black, \
'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt palette notitle
So, we first plot the data without legend in black, then plot the data points but no legend. The nice thing about this approach is that there is no need to fix the x or y range.
I would just create a dummy line and use notitle on the real lines. Something like
set yrange[0:1]
plot "realdata1.data" u 1:2 w linespoints lt 1 notitle , \
"realdata2.data" u 1:2 w linespoints lt 2 notitle , \
1/0 w linespoints lt 1 lc rgb 'black' title 'Model1', \
1/0 w linespoints lt 1 lc rgb 'black' title 'Model2'
Then replace lt 1 with whatever you have used for style in your current plot. Note that you'll need to use set yrange for gnuplot to accept the dummy curve

how to define X's label on gnuplot

This is My data :
18_AGT_s 8234.00 8234.00 8234.00
18_MAC_s 8414.36 8308.36 8246.33
9_MAC_r 8414.36 8308.36 8246.33
9_MAC_s 8414.55 8309.55 8246.45
8_MAC_r 8414.55 8309.55 8246.45
8_MAC_s 8414.56 8310.08 8246.47
6_MAC_r 8414.56 8310.08 8246.47
6_MAC_s 8416.19 8310.21 8246.49
1_MAC_r 8416.19 8310.21 8246.49
and here is my gnuplot code :
plot "dat" using ($0+1):2 with linespoints pt 8 ps 2 lt 2 lw 4 lc rgb
"green" title "DMSR","dat" using ($0+1):3 with linespoints pt 5 ps 2
lt 3 lw 4 lc rgb "blue" title "Alarm","dat" using ($0+1):4 with
linespoints pt 6 ps 2 lt 4 lw 4 lc rgb "red" title "Emergency"
and here is my out put :
But In the step part I want to have 18_AGT_s and 18_MAC_s and 9_MAC_s and .... for example on the X part I want to have 18_AGT_s in stand of 1 or I want to have 18_MAC_2 instand of 2 and 9_MAC_r instand of 3 etc. Any help thanks
Use the xticlabels() option with the column number with the labels as argument (1, in this case):
# Optionally rotate labels so they fit
set xtics rotate
plot "dat" using ($0+1):2 with linespoints pt 8 ps 2 lt 2 lw 4 lc rgb \
"green" title "DMSR","dat" using ($0+1):3 with linespoints pt 5 ps 2 \
lt 3 lw 4 lc rgb "blue" title "Alarm","dat" using \
($0+1):4:xticlabels(1) with linespoints pt 6 ps 2 lt 4 lw 4 lc rgb \
"red" title "Emergency"
Here you only need to use it for the last plot instance so that it overwrites the number options.

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