在GnuplotPy中设置行类型?

2024-09-29 23:30:45 发布

您现在位置:Python中文网/ 问答频道 /正文

在Gnuplot中,linetypelt标志允许用户选择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() 

输出如下: enter image description here


正如您在上面的代码中看到的,lt(线型)在Gnuplot.PlotItems.Data(..., with_=...)命令中。在普通Gnuplot中,我们只需lt 1来选择行类型1。然而,Gnuplot Py似乎随意地选择了线型(注意,在上面的图中有一条线是实线,而一条线是虚线)。让我们尝试两种在Gnuplot Py中手动更改行类型的策略。。。在

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

^{pr2}$

策略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

enter image description here

策略3。如果我添加gp('set style lt 1'),我会再次得到错误line 0: expecting 'data', 'function', 'line', 'fill' or 'arrow',并且图与上面显示的原始图相比没有变化。在


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


Tags: pyltdatawithline策略gp虚线
1条回答
网友
1楼 · 发布于 2024-09-29 23:30:45

这是有效的:

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)

结果如下: enter image description here

相关问题 更多 >

    热门问题