Skip to content Skip to sidebar Skip to footer

Change Color Limits With Quiver In Matplotlib?

How should the syntaxis be for changing the limits of the color range when plotting with quivers in matplotlib? I have the following code: PyPlot.ion() xlim(1, 64) ylim(1, 64) flec

Solution 1:

Okey, I got it, this is the right way to do it with matplotlib 1.3.1

figure()
xlim(1,64)
ylim(1,64)
flechitas=quiver(x,y,EFx,EFy, sqrt((EFx.*EFx+EFy.*EFy)), units="x", 
pivot="middle", cmap="Blues", width=0.4);
cb=colorbar(flechitas, clim(0,120));

So, clim(min, max) must be an argument to colorbar(...), it seems.

Solution 2:

Use the matplotlib function clim():

plt.clim(0,120)

Extended example:

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)
M = np.hypot(U, V)

plt.figure(figsize=(17,5))
plt.subplot(121)
Q = plt.quiver(X, Y, U, V, M)
plt.colorbar()
plt.subplot(122)
Q = plt.quiver(X, Y, U, V, M)
plt.colorbar()
plt.clim(0,1)

enter image description here

Post a Comment for "Change Color Limits With Quiver In Matplotlib?"