在更新版本的matplotlib(2.0.0)中使用LineCollection
时,绘图中的线条大小与图例中句柄的线条大小不匹配。由于句柄的行比绘图中的行大,因此需要使用handlelength
,以便破折号贯穿整个循环,但问题是图例中的行仍然较大。如何使它们与图上的尺寸相同?。请参见以下示例:
lines1 = [[(0, .5), (.5, 1)], [(.3, .6), (.2, .2)]]
lines2 = [[[0.7, .2], [.8, .4]], [[.5, .7], [.6, .1]]]
lc1 = matplotlib.collections.LineCollection(lines1, linestyles="--")
lc2 = matplotlib.collections.LineCollection(lines2, linestyles="-.")
fig, ax = plt.subplots()
ax.add_collection(lc1)
ax.add_collection(lc2)
ax.legend([lc1,lc2],["line1","line2"],handlelength=3)
好吧。上一个绘图是用matplotlib版本2.0.0b4+2415.g6ad368b绘制的。现在我尝试使用matplotlib版本1.5.3,并且plot中的线和图例中的line句柄之间没有不匹配。所以matplotlib的更新版本出了问题(改变了)。在
^{pr2}$
发生这种情况是因为the dash patterns now scale with line width但是与
LineCollection
关联的图例句柄似乎没有正确处理(看起来像一个bug)。您可以按照链接中的说明恢复旧的行为。在相关问题 更多 >
编程相关推荐