matplotlib / matplotlib/matplotlib

Add ability to add QuiverKey object to Legend

Open
#16,664 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

New feature topic: arrow topic: legend
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Feature Request

**Feature summary**
I'd like to be able to add the QuiverKey object to the legend as a handle. So the length of the arrow in the legend is meaningful to the quivers on the plot, but so it can be displayed in a tidy way with more mixed plot types. This was [mentioned on another issue](https://github.com/matplotlib/matplotlib/issues/2601/#issuecomment-33201027), but I don't think it's actually been implemented.

**Code for reproduction**
```python
from matplotlib.patches import Patch
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()

X = np.arange(-10, 10, 1)
Y = np.arange(-10, 10, 1)
U, V = np.meshgrid(X, Y)

q = ax.quiver(X, Y, U, V)

qk = ax.quiverkey(q, 0.9,0.8, U=10, label='QK length = 10', labelpos='E')

legend_elements = [
Patch(facecolor="red", edgecolor="black", label="First Element"),
qk
]

ax.legend(handles=legend_elements)

plt.show()
```

**Actual outcome**

```
/opt/conda/envs/py37/lib/python3.7/site-packages/ipykernel_launcher.py:20: UserWarning: Legend does not support instances.
A proxy artist may be used instead.
See: http://matplotlib.org/users/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists
```

**Expected outcome**
Have the quiverkey as another element in the legend box with my other proxies. If I create a proxy as the error suggests, it will lose it's meaningful length and therefore it's value as a "key".

**Matplotlib version**
* Operating system: Linux Mint
* Matplotlib version: 3.1.2
* Matplotlib backend: module://ipykernel.pylab.backend_inline
* Python version: 3.7.3

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

Start by running the supplied Python reproduction and inspect Matplotlib's legend handling alongside the QuiverKey object. The feature is done when a QuiverKey can be passed as a legend handle without a warning and its meaningful arrow length is preserved alongside other legend entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.