matplotlib / matplotlib/matplotlib
hist reverses legend order if histtype is not bar
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 23.2k
- Forks
- 8.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 66
Description
Matplotlib v2.0.x and master on Python 3.5:
```python
x1 = np.random.randn(100)
x2 = np.random.rand(100)
plt.hist([x1, x2], label=['x1', 'x2'], histtype='step')
plt.legend()
```
**Actual outcome**

**Expected outcome**
With `histtype='bar'` the order of the variables is preserved, as I would expect, instead of reversed, as with `step`.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example using plt.hist with histtype='step' followed by plt.legend(), comparing it with histtype='bar'. Trace the histogram and legend handling from the plt.hist and plt.legend entry points; done means the x1 and x2 legend entries retain their input order for non-bar histogram types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100