在 matplotlib 中使用 quiver 更改颜色限制? [英] Change color limits with quiver in matplotlib?
问题描述
在 matplotlib 中使用 quivers 绘图时更改颜色范围限制的语法应该如何?我有以下代码:
PyPlot.ion()xlim(1, 64)ylim(1, 64)flechitas = quiver(x, y, EFx, EFy, sqrt((EFx.*EFx+EFy.*EFy)),枢轴=中",cmap=蓝调")cb=colorbar(flechitas)
产生一个足够的图像,但使用自动检测到的范围作为第 5 个参数(颜色).在
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)
flechitas = quiver(x, y, EFx, EFy, sqrt((EFx.*EFx+EFy.*EFy)),
pivot="middle", cmap="Blues")
cb=colorbar(flechitas)
Which produces an adecuate image but uses automatically detected range for the 5th argument (the color). In the manual of matplotlib it says that I can use the clim
keyword but if I put it inside the arguments or outside, after the xy limits, I get an error indicating that I must create an image first, with imageshow. If I do that, then I get a more obscure error, an AssertionError()
. My matplotlib is 1.3.1.
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)
这篇关于在 matplotlib 中使用 quiver 更改颜色限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!