Skip to content Skip to sidebar Skip to footer

Matplotlib Quiver Plot Matching Key Label Color With Arrow Color

Using matplotlib, python3.6. I am trying to create some quiverkeys for a quiver plot but having a hard time getting the label colors to match certain arrows. Below is a simplified

Solution 1:

Supposedly you meant to be using the color argument of quiver to set the actual colors.

import matplotlib.pyplot as plt

q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
             color=[(0.6, 0.8, 0.5, 1.0 ), (0.3, 0.1, 0.2, 1.0 )])
plt.quiverkey(q, .5, .5, 7, r'vector2', labelcolor=(0.3, 0.1, .2, 1),
                      labelpos='S', coordinates = 'figure')

plt.show()

enter image description here

Else, the C argument is interpreted as the values to map to colors according to the default colormap. Since you only have two arrows, only the first two values from the 8 numbers in the array given to the C argument are taken into account. But the colormap normalization uses all of those values, such that it ranges between 0.1 and 1.0. The call

q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
             [(0.6, 0.8, 0.5, 1.0 ), (0.3, 0.1, 0.2, 1.0 )])

is hence equivalent to

q=plt.quiver([1, 2,], [1, 1], [5,0], [5,5],
             [0.6, 0.8], norm=plt.Normalize(vmin=0.1, vmax=1))

resulting in the first arrows color to be the value of 0.6 in the viridis colormap normalized between 0.1 and 1.0, and the second arrow to 0.8 in that colormap.

This becomes apparent if we add plt.colorbar(q, orientation="horizontal"):

enter image description here

Post a Comment for "Matplotlib Quiver Plot Matching Key Label Color With Arrow Color"