Matplotlib Quiver Key Label Getting Cut
When copying the example in the docs the label associated with the quiver key is not showing up. Any thoughts? Edit: Thanks all for your responses. @X helped me realize the differe
Solution 1:
My guess is that somehow your backend is changing the figure size on you and that moves the quiver key. Why do you want it in figure co-ordinates? Suggest you position it relative to the axes:
import matplotlib.pyplot as plt
import numpy as np
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
U = np.cos(X)
V = np.sin(Y)
fig1, ax1 = plt.subplots()
ax1.set_title('Arrows scale with plot width, not view')
Q = ax1.quiver(X, Y, U, V, units='width')
qk = ax1.quiverkey(Q, 1.0, 1.02, 2, r'$2 \frac{m}{s}$', labelpos='E',
coordinates='axes')
plt.show()
Solution 2:
There is a difference between using a coordinate reference as an axis and a figure. The background color of the figure is pink and the background color of the axis is yellow.
qk = ax1.quiverkey(Q, 0.85, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E', coordinates='figure')
qk = ax1.quiverkey(Q, 0.85, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E', coordinates='axes')
Solution 3:
When in doubt, tight_layout! (it's a bit of a quick/easy fix, vs. fiddling forever with various margin attributes)
import matplotlib.pyplot as plt
import numpy as np
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
U = np.cos(X)
V = np.sin(Y)
fig1, ax1 = plt.subplots()
ax1.set_title('Arrows scale with plot width, not view')
Q = ax1.quiver(X, Y, U, V, units='width')
qk = ax1.quiverkey(Q, 0.92, .95, 2, r'$2 \frac{m}{s}$', labelpos='E',
coordinates='figure')
plt.tight_layout()
plt.show()
Post a Comment for "Matplotlib Quiver Key Label Getting Cut"