I am trying to set the absolute quiverkey
arrow-length matching a specific arrow-length of my quiver
data. Can somebody enlighten me how the quiverkey
argument U
works or at least how to scale it to my needs?
Background
Python version: 3.6.5
matplotlib version: 3.0.0
Minimal example
I've slightly modified the example from: https://matplotlib.org/gallery/images_contours_and_fields/quiver_simple_demo.html#sphx-glr-gallery-images-contours-and-fields-quiver-simple-demo-py
import matplotlib.pyplot as plt
import numpy as np
X = np.arange(-10, 11, 2)
Y = np.arange(-10, 11, 2)
U, V = np.meshgrid(X, Y)
# calculate length of each arrow
data_arrow_length = np.abs(np.sqrt(np.square(U[:]) + np.square(U[:])))
# set displayed arrow length for longest arrow
displayed_arrow_length = 2
# calculate scale factor for quiver
scale_factor = np.max(data_arrow_length)/displayed_arrow_length
# mysterious arrow length for quiverkey
quiverkey_length = 200
fig, ax = plt.subplots()
q = ax.quiver(X, Y, U, V, pivot='middle',
units='xy', width=0.1,
scale=scale_factor, scale_units='xy')
ax.quiverkey(q, X=0.3, Y=1.1, U=quiverkey_length,
label='Quiver key, length = 10', labelpos='E')
plt.show()
This way I can control the maximal arrow-length displayed with quiver
using displayed_arrow_length
. In this example the maximal data_arrow_length
is approx. 14 and is displayed with an arrow length of 2 based on xy-data.
Problem
If I run the above example I get:
However, if I maximize the figure window I get:
The quiverkey
arrow-length does not scale with my quiver
arrows and I had to use an randomly high number for quiverkey_length
to appear altogether.
Question
I would like to set the quiverkey
arrow length to a specific value as displayed with quiver
, for example 10. However, it does not appear to scale with the data at all. How can I achieve this?
It appears this was a bug in matplotlib which has been fixed now.
related github issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With