我试图用python绘制一组数据。我正在使用matplotlib.pyplot图书馆来做这件事。在
我做了所有的工作,但我有一个问题,在图例中的最后一个键出现了一个奇怪的格式比其他的。我试着做不同的设置来修复这个问题,但到目前为止没有运气。。。有谁能帮我修复CH4(A)以与其他键相同的格式显示吗?在
格式看起来很像这在情节(我不能张贴照片,直到我得到10个声誉
CH1(A)
CH2(A)
CH3(A)
甲烷
(一)
)
这是我设置传奇的代码。在legends = data[16]
legends = legends.split(",")
if numChannels == 1:
plt.plot(raw[:,0],raw[:,1], label=legends[1] + " (" + units[1] + ")")
elif numChannels == 2:
plt.plot(raw[:,0],raw[:,1], label=legends[1] + " (" + units[1] + ")")
plt.plot(raw[:,0],raw[:,2], label=legends[2] + " (" + units[2] + ")")
elif numChannels == 3:
plt.plot(raw[:,0],raw[:,1], label=legends[1] + " (" + units[1] + ")")
plt.plot(raw[:,0],raw[:,2], label=legends[2] + " (" + units[2] + ")")
plt.plot(raw[:,0],raw[:,3], label=legends[3] + " (" + units[3] + ")")
elif numChannels == 4:
plt.plot(raw[:,0],raw[:,1], label=legends[1] + " (" + units[1] + ")")
plt.plot(raw[:,0],raw[:,2], label=legends[2] + " (" + units[2] + ")")
plt.plot(raw[:,0],raw[:,3], label=legends[3] + " (" + units[3] + ")")
plt.plot(raw[:,0],raw[:,4], label=legends[4] + " (" + units[4] + ")")
plt.legend(loc=0)
plt.xlabel(legends[0])
plt.ylabel("Data")
plt.title(filestr)
plt.show()
图例是我从.csv文件中读取的数据。我不太清楚为什么会这样。这只发生在最后一个传说中。E、 g.如果我有4个数据集和绘图3,它们会很好地显示出来,但是如果我全部绘制4个数据集或只有1个数据集并绘制,键的格式与上面所示的不同。在