8000 Legend for lines created using `LineCollection` show different handle line scale. · Issue #7814 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Legend for lines created using LineCollection show different handle line scale. #7814
Closed
@pmreyes2

Description

@pmreyes2

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"])

fig_2 0 0rc2

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"])

workaround

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0