Closed
Description
Legend for lines created using LineCollection
show different handle scale as lines in the plot
When using LineCollection
there is a mismatch of the line scales in the plot an the lines of the handle in the legend.
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"])
A workaround found by Goyo in the answer for stackoverflow question was to turn off scale_dashes
:
classic_dashes = {
'lines.dashdot_pattern': [5, 4, 2, 3],
'lines.dashed_pattern': [6, 6],
'lines.scale_dashes': False
}
with plt.rc_context(classic_dashes):
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="--", linewidths=2)
lc2 = matplotlib.collections.LineCollection(lines2, linestyles="-.", linewidths=2)
fig, ax = plt.subplots()
ax.add_collection(lc1)
ax.add_collection(lc2)
ax.legend([lc1,lc2],["line1","line2"])
Matplotlib version
- The matplotlib version used is 2.0.0rc2+2995.gd7879bc
- When using old matplotlib version 1.5.3 which doesn't have
scale_dashes
activated, there is no scaling problem between legend and plot lines.
Metadata
Metadata
Assignees
Labels
No labels