我正在检查下面的matplotlib示例,并发现了一些我觉得很奇怪的事情。
import matplotlib.pyplot as plt
line1, = plt.plot([1,2,3], label="Line 1", linestyle='--')
line2, = plt.plot([3,2,1], label="Line 2", linewidth=4)
line3, = plt.plot([4,5,6], label='Line 3')
line4, = plt.plot([-4,-5,-6], label='Line 4')
# Create a legend for the first line.
first_legend = plt.legend(handles=[line1, line3], loc=1)
# Add the legend manually to the current Axes.
ax = plt.gca().add_artist(first_legend)
# Create another legend for the second line.
plt.legend(handles=[line2, line4], loc=4)
plt.show()
为什么我们需要在行中添加一个尾随逗号才能生效?