8000 [Bug]: Unintuitive matching of line styles and labels in legend · Issue #27725 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: Unintuitive matching of line styles and labels in legend #27725
Open
@maxaehle

Description

@maxaehle

Bug summary

In a figure with one plt.errorbar and one plt.plot line, legend text must be supplied in a counterintuitive order.

Code for reproduction

import matplotlib.pyplot as plt
plt.errorbar([0,1],[0,1],[.3,.3])
plt.plot([0,1],[1,0])
plt.legend(["increasing","decreasing"])
plt.show()

Actual outcome

The legend associates the plt.plot line with increasing and the plt.errorbar line with the label decreasing.

actual_outcome

Expected outcome

The two line styles in the legend should be swapped. I.e., the plt.errorbar line should be associated with the label increasing and the plt.plot line with the label decreasing.

Additional information

The user can work around the issue by providing the legend text to plt.errorbar/plt.plot via the keyword argument label.

The documentation of legend says about the way we use it (supplying only label text) that

This call signature is discouraged, because the relation between plot elements and labels is only implicit by their order and can easily be mixed up.

Operating system

Ubuntu 22.04

Matplotlib Version

3.5.1

Matplotlib Backend

TkAgg

Python version

3.10.12

Jupyter version

N/A

Installation

None

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

      2B2A
      0