【问题标题】:Setting line type in GnuplotPy?在 GnuplotPy 中设置线型?
【发布时间】:2012-12-14 06:11:48
【问题描述】:

在 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() 

这是输出:


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

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

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

策略 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',并且情节与上面显示的原图没有变化。


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

【问题讨论】:

  • 策略3应该是gp('set style line 1 lc rgb "blue"')

标签: python visualization gnuplot data-visualization


【解决方案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)

结果如下:

【讨论】:

    猜你喜欢
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多