matplotlib / matplotlib/matplotlib

hist reverses legend order if histtype is not bar

Open
#8,461 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

keep topic: hist
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**
![hist_reversed_order](https://cloud.githubusercontent.com/assets/85125/24885448/2a5c2e82-1dea-11e7-9429-05d3f2ae055a.png)

**Expected outcome**

With `histtype='bar'` the order of the variables is preserved, as I would expect, instead of reversed, as with `step`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.