我使用pcolor绘制2D数组中的信息。但是,数组中的信息在迭代过程中会发生变化,我希望动态更新颜色映射,以便实时可视化更改。最简单的方法是什么?
编辑-示例:
编辑-示例:
from __future__ import division
from pylab import *
import random
n = 50 # number of iterations
x = arange(0, 10, 0.1)
y = arange(0, 10, 0.1)
T = zeros([100,100]) # 10/0.1 = 100
X,Y = meshgrid(x, y)
"""initial conditions"""
for x in range(100):
for y in range(100):
T[x][y] = random.random()
pcolor(X, Y, T, cmap=cm.hot, vmax=abs(T).max(), vmin=0)
colorbar()
axis([0,10,0,10])
show() # colormap of the initial array
"""main loop"""
for i in range(n):
for x in range(100):
for y in range(100):
T[x][y] += 0.1 # here i do some calculations, the details are not important
# here I want to update the color map with the new array (T)
谢谢
imshow
代替pcolor
吗? - tacaswellimshow
有一个几乎微不足道的方法来更新数据,而pcolor
则返回一个相对较难更新的PolyCollection
。 - tacaswellT += .1
替换掉你嵌套的循环(关于x
和y
的循环)。 - tacaswell