8000 [Bug]: Global legend weird behaviors · Issue #26841 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: Global legend weird behaviors #26841
Closed
@imxtx

Description

@imxtx

Bug summary

The color of the global legend for all subplots does not match the label colors.

Code for reproduction

esbs = np.array(list(range(0,41)))
lines = [e for e in asrs]

colors = ['dodgerblue', 'tomato', 'yellowgreen', 'orange', 'dodgerblue', 'tomato', 'yellowgreen', 'orange']
labels = ['A', 'C', 'M','F','A+', 'C+', 'M+','F+',]
linestyles = ['-', '-','-', '-','--','--','--', '--']

fig, axs = plt.subplots(2, figsize=(6, 6), sharex=False)

handles = []
for i in range(8):
    print(i, colors[i], labels[i])
    if i == 3 or i == 7:
        h = axs[1].plot(esbs, lines[i], color=colors[i], linewidth=1.2, linestyle=linestyles[i], label=labels[i])
    else:
        h = axs[0].plot(esbs, lines[i], color=colors[i], linewidth=1.2, linestyle=linestyles[i], label=labels[i])
    handles.append(h)

fig.legend(handles, labels=labels, ncol=2, bbox_to_anchor=(0.15, 1.06), loc='upper left')

plt.show()

Actual outcome

image

Expected outcome

The colors for legend F and legend F+ should be orange. But they are different.

Additional information

No response

Operating system

No response

Matplotlib Version

3.7.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0