【发布时间】:2016-02-23 02:07:47
【问题描述】:
我正在尝试使用此示例:http://matplotlib.org/examples/api/two_scales.html#api-two-scales 用我自己的数据集如下所示:
import sys
import numpy as np
import matplotlib.pyplot as plt
print sys.argv
logfile = sys.argv[1]
data = []
other_data =[]
with open(logfile,'rb') as f:
for line in f:
a = line.split(',')
print a
data.append(a[1])
other_data.append(a[2][:-1])
print other_data
x = np.arange(0,len(data))
fig,ax1 = plt.subplots()
ax1.plot(x,np.arange(data))
ax2 = ax1.twinx()
ax2.plot(x,np.arange(other_data))
plt.show()
但是,我不断收到此错误:
'Traceback (most recent call last):
File "share/chart.py", line 17, in <module>
ax1.plot(x,np.arange(data))
TypeError: unsupported operand type(s) for -: 'list' and 'int'
我认为我正确使用了 twinx 命令,但显然没有。我该怎么做?
【问题讨论】:
-
错误似乎不是源自
twinx,当它们被传递给绘图函数时,它似乎位于x或np.arange(data)。我会检查以确保他们输出您期望的内容。
标签: python matplotlib