matplotlib / matplotlib/matplotlib

[Bug]: quiverkey behavior with quiver(scale_units="xy")

Open
#27,008 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Bug summary

I observed a result that is not documented and want help to determine whether this is the desired behavior:

Below is a script from `test_quiver.py`. In the last line we want to plot (in the lower ax) a `quiverkey` in the with 45 degree. My understand is that `angle` specified in `quiverkey` is for the rectangular canvas we are drawing on, therefore, independent of what we are plotting, what the coordinate axes look like. So it should be 45 degree from horizontal axis.

The current implementation attempts to map the `angle` to other things if `scale_units='xy'` or `angle='xy'` is set in `quiver()`. This mapping is problematic and is the root cause of issues like https://github.com/matplotlib/matplotlib/issues/26316 and https://github.com/matplotlib/matplotlib/issues/26748. I found something else in `Quiver` that also needs to be fixed, so it's not a one-liner fix that I talked about today... I will post more details about the investigation and possible fix in a PR later.

Old business for recap: On the call today, we discussed about that `angle` in QuiverKey() should be calculated from x-axis or horizontal-axis, I guess we are not opposed to the idea of "horizontal-axis"?

### Code for reproduction

```python
X = np.arange(8)
Y = np.zeros(8)
angles = X * (np.pi / 4)
uv = np.exp(1j * angles)
U = uv.real
V = uv.imag
fig, axs = plt.subplots(2)
for ax, angle_str in zip(axs, ('uv', 'xy')):
ax.set_xlim(-1, 8)
ax.set_ylim(-0.2, 0.2)
q = ax.quiver(X, Y, U, V, pivot='middle',
units='xy', width=0.05,
scale=2, scale_units='xy',
angles=angle_str)
print(X, Y, U, V, sep="\n")
ax.scatter(X, Y)
ax.plot([1, 1.7], [0, 0.7])
for x, angle in zip((0.2, 0.5, 0.8), (0, 45, 90)):
ax.quiverkey(q, X=x, Y=0.8, U=1, angle=angle, label='', color='b')
```

### Actual outcome

The blue arrow in the bottom is not 45 degree
image

### Expected outcome

The blue arrow in the bottom is 45 degree
image

### Additional information

_No response_

### Operating system

_No response_

### Matplotlib Version

3.90dev

### Matplotlib Backend

_No response_

### Python version

_No response_

### Jupyter version

_No response_

### Installation

None

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 with the reproduction in test_quiver.py and compare the two quiver calls using angles="uv" and angles="xy". Inspect the Quiver and QuiverKey angle handling; done means the lower plot's quiverkey renders the requested 45-degree angle while preserving the relevant existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
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.