Skip to content

Custom legend wrong color drawn depending on variable name #2155

@klonuo

Description

@klonuo

For example (in pylab mode):

c = ['#0091D3', '#D41621', '#009737', '#FE6C19']
x = arange(10)

for z in range(4):
    plot(polyfit(x, random.random(10), 1), color=c[z], lw=2)

A = Line2D((0,1),(0,0), color=c[0], lw=2)
B = Line2D((0,1),(0,0), color=c[1], lw=2)
C = Line2D((0,1),(0,0), color=c[2], lw=2)
D = Line2D((0,1),(0,0), color=c[3], lw=2)

legend((A, B, C, D), ('A', 'B', 'C', 'D'), loc=2)

result:

screenshot

but if I name Line2D variables like this:

A2 = Line2D((0,1),(0,0), color=c[0], lw=2)
B2 = Line2D((0,1),(0,0), color=c[1], lw=2)
A1 = Line2D((0,1),(0,0), color=c[2], lw=2)
B1 = Line2D((0,1),(0,0), color=c[3], lw=2)

legend((A2, B2, A1, B2), ('A2', 'B2', 'A1', 'B1'), loc=2)

I get incorrect color for last line:

screenshot

Latest stable MPL on Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions