用Matplotlib给子图添加图例时出错ax.legend() TypeError zip argument #2 must support iteration

画图时添加图例

import matplotlib.pyplot as plt
line_up, = plt.plot([1,2,3])
plt.legend(line_up, 'Up')
plt.show()

报错zip argument #2 must support iteration
应该是legend的参数需要zip形式。
(for label,handle in zip (labels,handles)
所有改写成下面形式就好了

import matplotlib.pyplot as plt
line_up, = plt.plot([1,2,3])
plt.legend((line_up,), ('Up',))
plt.show()

参考: lhttps://stackoverflow.com/questions/43326938/typeerror-zip-argument-2-must-support-iteration-with-matplotlib-pyplot-legend.

你可能感兴趣的:(画图)