我用line, = ax.plot([1, 2, 3], label='Inline label')
# Overwrite the label by calling the method.
line.set_label('Label via method')
ax.legend()
保存了画布json,当我使用import matplotlib.pyplot as plt
line1, = plt.plot([1,2,3], label='A')
line2, = plt.plot([2,3,4], label='B')
ax = plt.gca()
l = ax.get_legend_handles_labels()
print(l)
line1.set_label("C")
line2.set_label("D")
ax.legend()
l = ax.get_legend_handles_labels()
print(l)
plt.show()
>>([<matplotlib.lines.Line2D object at 0x000000000A399EB8>, <matplotlib.lines.Line2D object at 0x0000000008A67710>], ['A', 'B'])
>>([<matplotlib.lines.Line2D object at 0x000000000A399EB8>, <matplotlib.lines.Line2D object at 0x0000000008A67710>], ['C', 'D'])
时,所有画布对象都存在且没事,但画布元素上的事件不起作用,默认画布设置(如renderOnAddRemove,selection )不起作用;我做错了什么?对不起我的英语不好。