[英]Error message installing “Gnuplot-py” with “python setup.py install” command in Mac OS Sierra
I'm trying to install the "Gnuplot-py" package on my Mac using this command "python setup.py install" within the gnuplot-py-1.8 directory but I get this error: 我正在尝试使用gnuplot-py-1.8目录中的“ python setup.py install”命令在Mac上安装“ Gnuplot-py”软件包,但出现此错误:
Traceback (most recent call last): 追溯(最近一次通话):
File "/Users/sebydc77/Downloads/gnuplot-py-1.8/PlotItems.py", line 20, in from cStringIO import StringIO ModuleNotFoundError: No module named 'cStringIO'
从cStringIO导入文件“ /Users/sebydc77/Downloads/gnuplot-py-1.8/PlotItems.py”,第20行,导入StringIO ModuleNotFoundError:没有名为“ cStringIO”的模块
During handling of the above exception, another exception occurred: 在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last): 追溯(最近一次通话):
File "setup.py", line 15, in from init import version File "/Users/sebydc77/Downloads/gnuplot-py-1.8/ init .py", line 166, in from PlotItems import PlotItem, Func, File, Data, GridData File "/Users/sebydc77/Downloads/gnuplot-py-1.8/PlotItems.py", line 22, in from StringIO import StringIO ModuleNotFoundError: No module named 'StringIO'
init导入版本中的文件“ setup.py”,第15行,从PlotItems中导入文件“ /Users/sebydc77/Downloads/gnuplot-py-1.8/ init .py”,行166,导入PlotItem,Func,File,Data, GridData文件“ /Users/sebydc77/Downloads/gnuplot-py-1.8/PlotItems.py”,第22行,从StringIO导入StringIO ModuleNotFoundError:没有名为“ StringIO”的模块
I spent at least 3 hours trying to solve this problem. 我花了至少3个小时试图解决这个问题。 I also tried different alternatives such as "pip install Gnuplot-py", "pip install download link..." etc...
我还尝试了其他替代方法,例如“ pip install Gnuplot-py”,“ pip install download link ...”等。
(NOTE: I already have gnuplot installed on my machine) (注意:我的机器上已经安装了gnuplot)
As mentioned, the module doesn't work with Python 3. 如前所述,该模块不适用于Python 3。
But it isn't all that hard to write a custom plot function using gnuplot
in Python. 但是,在Python中使用
gnuplot
编写自定义绘图函数并不难。 Below is an example that I wrote to make a graph of the infusion of carbon fiber laminates with epoxy resin. 下面是我写的一个示例,用于绘制碳纤维层压板与环氧树脂的灌注图。 During the infusion, the pail of resin is placed on a scale, so I can write down the remaining weight every couple of minutes.
在输液过程中,将一桶树脂放在秤上,这样我每隔几分钟就可以写下剩余的重量。
The main input for the plot
function is a numpy
array where I have recorded the time and amount of resin still in the bucket. plot
函数的主要输入是一个numpy
数组,在这里我记录了桶中仍残留的树脂的时间和数量。 This amount goes down over time, so I use this data to calculate the total amount of injected resin at every point and the speed with which the resin flows. 该数量随时间下降,因此我使用此数据来计算每个点处注入的树脂总量以及树脂流动的速度。 That's where
numpy
comes in handy! 那是
numpy
派上用场的地方!
Basically this function creates a list of lines containing gnuplot commands and inline data, which is then joined into a single string and fed to gnuplot
running as a subprocess
. 基本上,此函数创建一个包含gnuplot命令和行内数据的行列表,然后将这些行连接到单个字符串中,并馈给作为
subprocess
gnuplot
运行的gnuplot
。
import subprocess
import numpy as np
def plot(rawdata, filename, maxy=None, labels=False, n=2):
"""Plot injection data with gnuplot.
Arguments:
data: numpy array of shape (N,2)
(Time, weight) pairs as written down during the injection. The time
in minutes increases and the weight in grams decreases.
filename: string
Name to write the output figure to.
maxy: Maximum y coordinate for the left axis (injected weight).
The right axis (injection speed) is 1/10th of the left axis.
When set to None, automatic scaling is used.
labels: Label every n-th data point when true.
n: Print every n-th value as a label.
"""
gtype = 'lines'
if labels:
gtype = 'linespoints'
delta = rawdata[1:] - rawdata[:-1]
totals = np.array([[0, 0]] + [[dt, -dm] for dt, dm in delta])
som = np.cumsum(totals, axis=0)
print('harshoeveelheid "{}": {} g'.format(filename, som[-1, 1]))
if maxy is None:
maxy = round(som[-1, 1], -2)
dm = np.array([[0]] + [[-dm/dt] for dt, dm in delta])
newdata = np.hstack((som, dm))
newdata[0, 2] = newdata[1, 2]
l1 = 'set label "{:.0f} g" at {},{} center offset 0,0.5'
l2 = 'set label "{:.0f} g/min" at {},second {} center offset 0,0.5'
p1 = 'plot "-" with {gt} ls 1 title "harshoeveelheid", ' \
'"-" with {gt} axes x1y2 ls 2 title "injectiesnelheid"'
lp1 = ', "-" using 1:2:2 with labels right offset character 0.4,0.7' \
'font "Alegreya, 8" tc ls 1 notitle'
lp2 = ', "-" using 1:2:2 axis x1y2 with labels left offset character ' \
'0.5,0.7 font "Alegreya, 8" tc ls 2 notitle'
text = ['set terminal pdfcairo enhanced color dashed font "Alegreya, 11" '
'rounded size 12.8 cm, 7.0 cm',
'set xlabel "tijd [min]"',
'set ylabel "harshoeveelheid [g]"',
'set y2label "injectiesnelheid [g/min]"',
'set y2tics',
'set yrange [0:{:.0f}]'.format(maxy),
'set y2range [0:{:.0f}]'.format(maxy/10),
'set key left bottom',
'set grid']
if not labels:
text.append(l1.format(newdata[-1, 1], newdata[-1, 0], newdata[-1, 1]))
text.append(l2.format(newdata[-1, 2], newdata[-1, 0], newdata[-1, 2]))
text.append('set output "{}"'.format(filename + '.pdf'))
text.append(p1.format(gt=gtype))
if labels:
text[-1] += lp1 + lp2
data1 = ['{:2.0f} {:4.0f}'.format(a, b) for a, b, _ in newdata]
data2 = ['{:2.0f} {:4.0f}'.format(a, b) for a, _, b in newdata]
text += data1
text.append('e')
text += data2
text.append('e')
if labels:
data1 = ['{:2.0f} {:4.0f}'.format(a, b) for a, b, _ in newdata[n-1::n]]
data2 = ['{:2.0f} {:4.0f}'.format(a, b) for a, _, b in newdata[n-1::n]]
text += data1
text.append('e')
text += data2
text.append('e')
p = subprocess.Popen(['gnuplot'], stdin=subprocess.PIPE)
_, _ = p.communicate(input='\n'.join(text).encode('utf-8'))
The output looks something like this: 输出看起来像这样:
Note that the style of the graph is determined by the settings in my gnuplotrc
file. 请注意,图的样式由
gnuplotrc
文件中的设置确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.