我想在一张图中绘制3个类似的数据,所以我尝试了这段代码:
f1 = open('C:/data/EF2011S.txt', 'r')
f2 = open('C:/data/EF2012S.txt', 'r')
f3 = open('C:/data/EF2013S.txt', 'r')
x1_start, x1_end = 1, 365
y1_start, y1_end = 1, 365 #
y11_start, y11_end = 1, 365 #
x2_start, x2_end = 1, 366
y2_start, y2_end = 1, 3 line
y21_start, y21_end = 1, 366
x3_start, x3_end = 1, 313
y3_start, y3_end = 1, 313
y31_start, y31_end = 1, 313
x1 = np.genfromtxt('C:/data/EF2011S.txt', usecols=(0))
y1 = np.genfromtxt('C:/data/EF2011S.txt', usecols=(5))
y11 = np.genfromtxt('C:/data/EF2011S.txt', usecols=(10))
x2 = np.genfromtxt('C:/data/EF2012S.txt', usecols=(0))
y2 = np.genfromtxt('C:/data/EF2012S.txt', usecols=(5))
y21 = np.genfromtxt('C:/data/EF2012S.txt', usecols=(10))
x3 = np.genfromtxt('C:/data/EF2013S.txt', usecols=(0))
y3 = np.genfromtxt('C:/data/EF2013S.txt', usecols=(5))
y31 = np.genfromtxt('C:/data/EF2013S.txt', usecols=(10))
x1 = x1[x1_start - 1:x1_end]
y1 = y1[y1_start - 1:y1_end]
y11 = y11[y11_start - 1:y11_end]
x2 = x2[x2_start - 1:x2_end]
y2 = y2[y2_start - 1:y2_end]
y21 = y21[y21_start - 1:y21_end]
x3 = x3[x3_start - 1:x3_end]
y3 = y3[y3_start - 1:y3_end]
y31 = y31[y31_start - 1:y31_end]
fig = plt.figure()
ax1 = fig.add_subplot(311)
ax1.set_title(" ")
ax1.set_xlabel(' ')
ax1.set_ylabel(' ')
ax1.plot(x1,y1,y11, c='r', label='the data')
ax2 = fig.add_subplot(312)
ax2.set_title(" ")
ax2.set_xlabel(' ')
ax2.set_ylabel(' ')
ax2.plot(x2,y2,y21, c='b', label='the data')
ax3 = fig.add_subplot(313)
ax3.set_title(" ")
ax3.set_xlabel(' ')
ax3.set_ylabel(' ')
ax3.plot(x3,y3,y31, c='g', label='the data')
leg1 = ax1.legend()
leg2 = ax2.legend()
leg3 = ax3.legend()
plt.show()
但我收到了错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
line 540, in runfile
execfile(filename, namespace)
File "C:/DATA2012/Plot1.py", line 58, in <module>
ax1.plot(x1,y1,y11, c='r', label='the data')
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 4137, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 317, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 279, in _plot_args
raise ValueError('third arg must be a format string')
ValueError: third arg must be a format string
错误是什么意思?
答案 0 :(得分:0)
每个&#y; y值&#39;参数必须与“x值”匹配。论点。试试
ax1.plot(x1,y1,x1,y11 ...)