我遇到谷歌搜索没有帮助的问题。我的代码扫描csv文件并查找行并将它们拉入列表。然后,我使用该列表绘制一堆东西。这很有效,直到我开始绘制我的第二个数字。我收到了这个错误:
C:\Program Files\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py:531: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
warnings.warn("No labelled objects found. "
这是我的代码:
import csv
import matplotlib.pyplot as plt
AHR2 = [] # Create an emppty lists
GPS = []
POS = []
CMD = []
BARO = []
NKF5 = []
ARSP = []
CURR = []
#Parse through data and place in lists
with open('data2.csv', 'r') as csvfile:
content = csv.reader(csvfile, delimiter=',')
for row in content:
if 'AHR2' == row[0]:
AHR2.append([row[0]] + list(map(float, row[1:])))
elif 'GPS' == row[0]:
GPS.append([row[0]] + list(map(float, row[1:])))
elif 'POS' == row[0]:
POS.append([row[0]] + list(map(float, row[1:])))
elif 'CMD' == row[0]:
CMD.append([row[0]] + list(map(float, row[1:])))
elif 'BARO' == row[0]:
BARO.append([row[0]] + list(map(float, row[1:])))
elif 'NKF5' == row[0]:
NKF5.append([row[0]] + list(map(float, row[1:])))
elif 'ARSP' == row[0]:
ARSP.append([row[0]] + list(map(float, row[1:])))
elif 'CURR' == row[0]:
CURR.append([row[0]] + list(map(float, row[1:])))
AHR2 = list(zip(*AHR2)) #transpose
GPS = list(zip(*GPS))
POS = list(zip(*POS))
CMD = list(zip(*CMD))
BARO = list(zip(*BARO))
NKF5 = list(zip(*NKF5))
ARSP = list(zip(*ARSP))
##############################################################################
########################## 1st Figure ##################################
##############################################################################
fig1 = plt.figure(figsize= (10,10))
AHR2_TIME = [x/1000000 for x in AHR2[1]]
GPS_TIME = [x/1000000 for x in GPS[1]]
POS_TIME = [x/1000000 for x in POS[1]]
ax = fig1.add_subplot(311)
ax.plot(AHR2_TIME, AHR2[5], label='AHR2 Alt', color = 'red')
ax.plot(GPS_TIME, GPS[9], label='GPS Alt', color = 'blue')
ax.plot(POS_TIME, POS[4], label='POS Alt', color = 'black')
plt.legend(loc='best',prop={'size':10})
plt.grid(True)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Altitude_MSL (m)')
##############################################################################
CMD_TIME = [x/1000000 for x in CMD[1]]
BARO_TIME = [x/1000000 for x in BARO[1]]
NKF5_TIME = [x/1000000 for x in NKF5[1]]
ax1 = fig1.add_subplot(312, sharex=ax)
ax1.plot(CMD_TIME, CMD[11], label='CMD Alt', color = 'red')
ax1.plot(BARO_TIME, BARO[2], label='GPS Alt', color = 'blue')
ax1.plot(POS_TIME, POS[5], label='POS Alt', color = 'orange')
ax1.plot(NKF5_TIME, NKF5[6], label='POS Alt', color = 'green')
plt.legend(loc='best',prop={'size':10})
plt.grid(True)
ax1.set_xlabel('Time (s)')
ax1.set_ylabel('Altitude_HAL (m)')
##############################################################################
ARSP_TIME = [x/1000000 for x in ARSP[1]]
ax2 = fig1.add_subplot(313, sharex=ax)
ax2.plot(ARSP_TIME, ARSP[2], label='ARSP', color = 'red')
plt.legend(loc='best',prop={'size':10})
plt.grid(True)
ax2.set_xlabel('Time (s)')
ax2.set_ylabel('Airspeed (m/s)')
plt.tight_layout()
##############################################################################
########################## 2nd Figure ##################################
##############################################################################
fig2 = plt.figure(figsize= (10,10))
CURR = list(zip(*CURR))
CURR_TIME = [x/1000000 for x in CURR[1]]
ax3 = fig1.add_subplot(311)
ax3.plot(CURR_TIME, CURR[2], label='AHR2 Alt', color = 'red')
plt.legend(loc='best',prop={'size':10})
这是data2.csv的样子:
AHR2,5456,78,123,86,12
GPS,456,87,321,456,78,123
AHR2,654,48,64,321,84,32
ARSP,489,78,321,879,123
答案 0 :(得分:0)
我找到了。我不知道我是怎么错过它的。我改变了这一行
ax3 = fig1.add_subplot(311)
到这个
ax3 = fig2.add_subplot(311)