Description
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
.
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