I am trying to change the line style of my gnuplot graph (there is only one line, I have only a simple plot of y versus x)
However, when I type:
set style line 1 linecolor rgb '#0060ad' ... (or linewidth or whatever argument)
(& replot)
nothing happens... it seems that it doesn't recognise the plot as "line 1".. I also tried to change the line index to a different number or its name...
Could anybody please help what to put "set style ..." argument?
Thank you very much!
Gnuplot has linestyle and linetype:
set linetype 1 linecolor "yellow"
plot x
or
set style line 1 linecolor "magenta"
plot x linestyle 1
Using set linetype is the recommended way, line style is deprecated.
Note, that resetting the line type must be done with reset session (gnuplot version 5), reset alone doesn't work.
Related
I have some weird behavior on plotting parametric functions and/or their corresponding datablock when using lines.
The plot seem don't obey the linestyle (row 1), at the same time the default linetype applied seems reversed when comparing plots come from functions or datablock (row 2).
Curiously the plot seems to inherit the linewidth from linestyle (row 3).
Only when using linecolor (row 4) the plots looks like correct.
Here are the code, tested under 5.2.8 and 5.4 rc1 versions:
reset
set terminal pngcairo size 750,9.0 font ",10"
set output "parametric.png"
unset tics
unset border
set view equal xyz
set view ,,2
set view 100,30
set xyplane 0
set hidden3d
set parametric
set urange [0:2*pi]
set vrange [0:pi/2]
set style line 1 lc "red" lw 2
f(u,v) = cos(u)*cos(v)
g(u,v) = sin(u)*cos(v)
h(v) = sin(v)
set table $hemisphere
splot f(u,v), g(u,v), h(v)
unset table
set multiplot layout 4,2 columnsfirst
splot f(u,v), g(u,v), h(v) w l ls -1 t "Using functions (with ls -1 )"
splot f(u,v), g(u,v), h(v) w l lt 3 t "Using functions (with lt 3)"
splot f(u,v), g(u,v), h(v) w l ls 1 t "Using functions (with custom ls 1)"
splot f(u,v), g(u,v), h(v) w l lc "red" t "Using functions (with lc 'red')"
splot $hemisphere w l ls -1 t "Using datablock (with ls -1)"
splot $hemisphere w l lt 3 t "Using datablock (with lt 3)"
splot $hemisphere w l ls 1 t "Using datablock (with custom ls 1)"
splot $hemisphere w l lc "red" t "Using datablock (with lc 'red')"
unset multiplot
Additionally, if you taken a close look on surface it has a reversed line segment.
What is happen here? Am I missing something?
Basic reason:
From the docs (selected text from help hidden3d)
Syntax:
set hidden3d {defaults} |
{{offset <offset>} | {nooffset}}
[...]
The first option, `offset`, influences the linetype used for lines on the
'back' side. Normally, they are drawn in a linetype one index number higher
than the one used for the front, to make the two sides of the surface
distinguishable. You can specify a different linetype offset to add
instead of the default 1, by `offset <offset>`. Option `nooffset` stands for
`offset 0`, making the two sides of the surface use the same linetype.
Notice that there is no mention of linestyles, as opposed to linetypes. The hidden3d algorithm carries out a complicated process of assigning colors to individual line segments that is explicitly based on the numerical linetype. Generation of the line sample in the key is more generic. It apparently fails to duplicate exactly what happens if hidden3d is active, so let's call that much a bug.
Wrong color for one line segment: I think this must be due to round-off error somewhere. Minute changes to the view angle or even to the terminal size cause the artifact to go away.
Doesn't really help anything but explains why it is the way you see it: In gnuplot 5 the use of linetypes pretty much supplemented the older mechanism of linestyles. There is partial backwards compatibility via the command set style increment user, which triggers in many places where the program has to pick a color for the "next thing" whatever that might be. But it doesn't catch all the places where the multiple colors are involved, and hidden3d is one of those places.
I would like to add a gray dashed vertical line on my graph with GNUPLOT.
My terminal is;
set terminal postscript portrait enhanced color dashed lw 1 "DejaVuSans" 12 size 6,6
set output "pic.ps"
set xrange [30:110]
plot 'smth.txt' w lines ls 7 t ""
I have looked into several ideas around but there seems to no explanation about how to get a dashed gray line vertically at let's say x = 40 (the line gonna be parallel to y-axis)
The key is to use the set arrow command and remove the head to make it a line:
set arrow from 40,0 to 40,100 nohead lc rgb 'red' dt 2
Your graph does not specify any y value, so adjust it to a "larger than needed" value.
For dash type (dt), checkout p.42 of manual. It is terminal-dependent (I didn't tried with postscript), but you can adjust as needed.
I am trying to make a barplot with GNUplot, were each bar has a different color. I have found out in the manual that it can be done using lc rgbcolor variable.
My data folder looks like this,
ACB 0.106372
ASW 0.10909
BEB 0.110973
CDX 0.106577
CEU 0.102091
CHB 0.108829
CHS 0.110807
CLM 0.108803
My plot script is as follows,
set style histogram gap 2
set autoscale y
set style fill solid
set xtics rotate by 90 offset 0,-1.2
rgb(r,g,b) = 65536 * int(r*10) + 256 * int(g*10) + int(b*10)
set boxwidth .5
set output "Plot.eps"
plot "plot.tsv" using 2:xticlabels(1):(rgb($2,$2,$2)) with boxes lc rgb variable
I have used the rgb function that is shown in the GNUplot manual. But it shows the following error.
plot "plot.tsv" using 2:xticlabels(1):(rgb($2,$2,$2)) with boxes lc rgb variable
^
"#Plot.plt", line 18: x range is invalid
I can't figure out what the error means.
Please help.
Thanks in advance.
You are actually plotting with style "boxes", not "histograms". That probably is what you want, but whereas for histograms the x coordinate is implicit, for boxes you have to provide an x coordinate in the first column even if you're OK with the ordinal numbers 0,1,2,3,...
So
plot "plot.tsv" using 0:2:xticlabels(1):(rgb($2,$2,$2)) with boxes lc rgb variable
Oh, and you probably want to set the fillstyle also so that the colors are visible:
set style fill solid
I have created my first graph based on the input on stackoverflow. So my code is,
set title "Approximation Graph"
set term png
set output 'plot.png'
f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
fit f0_h(x) 'clk0_h' via 'clk0_h_c'
f1_h(x) = a1_h * x**2 + b1_h * x + c1_h
fit f1_h(x) 'clk1_h' via 'clk1_h_c'
f0_s(x) = a0_s * x**2 + b0_s * x + c0_s
fit f0_s(x) 'clk0_s' via 'clk0_s_c'
f1_s(x) = a1_s * x**2 + b1_s * x + c1_s
fit f1_s(x) 'clk1_s' via 'clk1_s_c'
set style data lines
plot "clk0_h" using 1:2, f0_h(x), "clk1_h" using 1:2, f1_h(x), "clk0_s" using 1:2, f0_s(x), "clk1_s" using 1:2, f1_s(x)
The graph is:
So I have major and minor question.
Major : is it possible to determine coefficient using gnuplot. As of
now, I determine manually. (some reason, I can not use numpy in python
for determine coefficient)
Minor : Can anyone refer me line property. 1) increase line width
2) change color 3) add a title for each line (to differentiate if they have same
color) 4) like I should have 8 line but some are overwrite
Concerning your first question: This is what fit actually does. In your script, by using via 'file.par' you only set starting values and specify the variables which are to be used for the fitting.
Just try the following:
f0_h(x) = a0_h * x**2 + b0_h * x + c0_h
fit f0_h(x) 'clk0_h' via a0_h, b0_h, c0_h
and see, if the coefficients come out well. By default, the starting values are assumed to be 1. If it doesn't work out, you may need to set the correct order of magnitude (set e.g. a0_h = 10 before fitting).
Regarding the minor stuff, use linewidth, linecolor etc. for the line properties. To specify the title, use title :).
You can define a linestyle for each function/data combination and use the line for the fit, and points for the data:
set style line 1 linecolor rgb 'red' linewidth 2 pointtype 4 linetype -1
set style line 2 linecolor rgb '#ff7700' pointtype 7 linetype 2
...
In this case, if you specify linecolor and linetype, the first determines the color, the second one the dash pattern (it the terminal supports it, see Gnuplot line types).
For the plotting, with the above kind of line style definitions, use e.g.
set style data points
set style func lines # these two settings are default
plot "clk0_h" using 1:2 linestyle 1 title 'clk0_h, data', \
f0_h(x) linestyle 1 title 'clk0_h, fit'
...
And you should consider using the pngcairo terminal, which creates much nicers graphics. Or, preferably, use a vector-based terminal, like pdfcairo.
Well, I'm trying to plot this graphic:
gnuplot> plot exp(-x) t 'MB' w l lw 3, (exp(x)-1)**(-1) w l lw 3 t 'BE', (exp(x)+1)**(-1) w l lw 3 t 'FD'
and exporting with
set terminal latex
How, or what, I have to do to the graphics be plotted in different lines styles, as dotted and dashed?
In order to specify line styles check the documentation here. You can specify the line type, line color, line width, point type etc.
To specify a blue dotted line on an X11 terminal do
set style line 1 lt 0 lc 3
plot x**2 ls 1
Note that the styles also depend on the terminal you are using. To see what possibilities there are use the test page of the current terminal by running test in your gnuplot console.
Examples of different line styles can be found here and there.