In Gnuplot, the linetype
or lt
flag allows the user to select the line type (dashed, dotted, solid, etc).
I'm using a Python wrapper called Gnuplot-Py. Here's an example:
import Gnuplot
data1 = [[3, 0.03], [4, 0.02], [5, 0.017]]
data2 = [[3, 0.027], [4, 0.015], [5, 0.014]]
gp = Gnuplot.Gnuplot(persist = 1)
gp('set terminal x11 size 350,225')
gp('set pointsize 2')
gp('set yrange [0.0:0.05]')
plot1 = Gnuplot.PlotItems.Data(data1, with_="linespoints lt rgb 'black' lw 6 pt 1", title="data1")
plot2 = Gnuplot.PlotItems.Data(data2, with_="linespoints lt rgb 'blue' lw 6 pt 8", title="data2")
gp.plot(plot2, plot1)
epsFilename='testLines.eps'
gp.hardcopy(epsFilename, terminal = 'postscript', enhanced=1, color=1) #must come after plot() function
gp.reset()
Here's the output:
As you can see in the above code, lt
(linetype) is in the Gnuplot.PlotItems.Data(..., with_=...)
commands. In plain Gnuplot, we would just do lt 1
to choose line type 1. However, Gnuplot-Py seems to arbitrarily choose the line type (notice that one line is solid, and one line is dashed in the above plot). Let's try a couple of strategies for manually changing the line type in Gnuplot-Py...
Strategy 1. I tried lt 1
instead of lt
in the with_
string. This throws an error, but it still produces the same plot as we saw above.
plot1 = Gnuplot.PlotItems.Data(data1, with_="linespoints lt 1 rgb 'black' lw 6 pt 1", title="data1") #returns the error `line 0: ';' expected
Strategy 2. I also tried removing lt
from the with_
string. This throws an error and ignores the formatting for the data1
line (see green line for data1
below).
plot1 = Gnuplot.PlotItems.Data(data1, with_="linespoints rgb 'black' lw 6 pt 1", title="data1") #returns the error `line 0: ';' expected
Strategy 3. If I add gp('set style lt 1')
, I again get the error line 0: expecting 'data', 'function', 'line', 'fill' or 'arrow'
, and the plot is unchanged from the original shown above.
This works:
with_="linespoints lt 1 lw 6 pt 1 linecolor rgb 'black'" #put this inside Gnuplot.PlotItems.Data() command
In my original post, I was doing with_="linespoints lt rgb 'black' ..."
. In other words, I was jumbling the linespoints
and linecolor
arguments together. I'm not sure why this didn't crash even when I didn't specify a linetype
.
Anyway, the takeaway is that we need this type of setup for the with_
string: linespoints (args to linespoints) linecolor (args to linecolor)
Here's the result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With