在Gnuplot中,linetype
或lt
标志允许用户选择line type(虚线、虚线、实线等)。在
我使用的是一个名为Gnuplot-Py的Python包装器。下面是一个例子:
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()
输出如下:
正如您在上面的代码中看到的,lt
(线型)在Gnuplot.PlotItems.Data(..., with_=...)
命令中。在普通Gnuplot中,我们只需lt 1
来选择行类型1。然而,Gnuplot Py似乎随意地选择了线型(注意,在上面的图中有一条线是实线,而一条线是虚线)。让我们尝试两种在Gnuplot Py中手动更改行类型的策略。。。在
策略1。我尝试了lt 1
而不是with_
字符串中的lt 1
。这抛出了一个错误,但它仍然产生了与我们上面看到的相同的图。在
策略2。我还尝试从with_
字符串中删除lt
。这将引发一个错误并忽略data1
行的格式(请参见下面的data1
的绿线)。在
plot1 = Gnuplot.PlotItems.Data(data1, with_="linespoints rgb 'black' lw 6 pt 1", title="data1") #returns the error `line 0: ';' expected
策略3。如果我添加gp('set style lt 1')
,我会再次得到错误line 0: expecting 'data', 'function', 'line', 'fill' or 'arrow'
,并且图与上面显示的原始图相比没有变化。在
这是有效的:
在我最初的帖子中,我在做
with_="linespoints lt rgb 'black' ..."
。换句话说,我把linespoints
和linecolor
参数混在一起。我不知道为什么即使我没有指定linetype
,它也没有崩溃。在总之,我们需要为
with_
字符串设置这种类型:linespoints (args to linespoints) linecolor (args to linecolor)
结果如下:
相关问题 更多 >
编程相关推荐