Issue
How can I put the legend of arrows drawn using pyplot.quiver
or pyplt.annotate
methods?
I'm currently using the following code:
import matplotlib.pyplot as plt
from numpy.random import *
x, y = [1, 2, 3], [0.5, 0.5, 0.5]
u1,v1 = randn(3), randn(3)
u2,v2 = randn(3), randn(3)
u3,v3 = randn(3), randn(3)
QV1 = plt.quiver(x, y, u1, v1, color='r')
QV2 = plt.quiver(x, y, u2, v2, color='b')
QV3 = plt.quiver(x, y, u3, v3, color='g')
I would like to put a simple legend which displays three different color arrows in such a simple way that,
plt.plot(x, y, color='r', label='red')
...
plt.legend()
Solution
You can use the quiverkey function to make a legend for arrows.
plt.quiverkey(QV1, 1.2, 0.515, 2, 'arrow 1', coordinates='data')
plt.quiverkey(QV2, 1.2, 0.520, 2, 'arrow 2', coordinates='data')
plt.quiverkey(QV3, 1.2, 0.525, 2, 'arrow 3', coordinates='data')
Answered By - Molly
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.