6

在 Gnuplot 中,linetypelt标志允许用户选择线条类型(虚线、点线、实线等)。

我正在使用一个名为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(linetype) 在Gnuplot.PlotItems.Data(..., with_=...)命令中。在普通的 Gnuplot 中,我们只lt 1需要选择线型 1。但是,Gnuplot-Py 似乎随意选择线型(请注意,在上图中,一条线是实线,一条线是虚线)。让我们尝试几种在 Gnuplot-Py 中手动更改线型的策略...

策略 1.我尝试lt 1了而不是ltwith_字符串中。这会引发一个错误,但它仍然会产生与我们在上面看到的相同的图。

plot1 = Gnuplot.PlotItems.Data(data1, with_="linespoints lt 1 rgb 'black' lw 6 pt 1", title="data1") #returns the error `line 0: ';' expected

策略2。我也尝试ltwith_字符串中删除。这会引发错误并忽略该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',并且情节与上面显示的原始内容没有变化。


如何在 GnuplotPy 中手动选择线型?

4

1 回答 1

1

这有效:

with_="linespoints lt 1 lw 6 pt 1 linecolor rgb 'black'" #put this inside Gnuplot.PlotItems.Data() command

在我原来的帖子中,我正在做with_="linespoints lt rgb 'black' ...". 换句话说,我把linespointslinecolor争论混在一起了。我不确定为什么即使我没有指定linetype.

无论如何,要点是我们需要这种类型的with_字符串设置:
linespoints (args to linespoints) linecolor (args to linecolor)

结果如下: 在此处输入图像描述

于 2012-12-31T21:49:59.813 回答