如何在python2.7.2中正确添加colorbar?

2024-09-28 01:25:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我很惊讶这听起来像是一个愚蠢的问题,但我有麻烦在我的数字周围编码彩色条。在

我花了一些时间阅读文档和这些示例: colorbar(可映射,cax=无,ax=无,使用_gridspec=True,**kw)

我不明白需要什么才能让它发挥作用。我通常会得到这样的错误: AttributeError:“AxesSubplot”对象没有属性“autoscale\u None”

我们稍后再考虑细节。在我的无花果上弹出一个自动缩放的颜色条的简单方法是什么。或者我应该先确定我的值的最小值和最大值吗?在

谢谢你的帮助!在

下面是代码(只有图1对我很重要),我知道它设计得很糟糕。开始是从以前的文件加载数据:

 from pylab import *
import matplotlib.animation as animation

from Tkinter import Tk 
from tkFileDialog import askopenfilename

Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file

with load(filename) as data:
    XYslice = data['XYslice']
    XZslice = data['XZslice']
    target = data['target']
    Over = data['Over']
    wvl=data['wvl']
    NA = data['NA']
    Dt = data['t']
    dz = data['dz']

Ntime,N,Nplans=shape(XZslice)
dxy=wvl/(2.0*NA)/Over 

thebigone=max(XYslice[:,N/2,N/2])
XZslice[0,0,0]=thebigone
XYslice[0,0,0]=thebigone



fig=figure(1,figsize=(12,6))
ax1=fig.add_subplot(1,2,1)
xlabel(r"$x (\mu m)$")
ylabel(r"$y (\mu m)$")
ax2=fig.add_subplot(1,2,2)
xlabel(r"$x (\mu m)$")
ylabel(r"$z (\mu m)$")

I=zeros(shape(Dt))
dI=zeros(shape(Dt))

im1=ax1.imshow(XYslice[0,:,:],interpolation='none')#,extent=[-N*dxy/2.0,N*dxy/2.0,-N*dxy/2.0,N*dxy/2.0],cmap='hot')
im2=ax2.imshow(XZslice[0,:,:],interpolation='none')#,extent=[-N*dxy/2.0,N*dxy/2.0,-Nplans*dz/2.0,Nplans*dz/2.0],cmap='hot')

for ii in range(len(Dt)):
    zedata=float64(((XYslice[ii,:,:]**2)[where(target==1)]).reshape(-1))
    dI[ii]=(sqrt(var(zedata)))
    I[ii]=(mean(zedata))

figure(2)
subplot(121)
plot(Dt,array(I),'o',Dt,array(dI))
grid('on')
subplot(122)
#plot(Dt,array(dI)/array(I))
xlabel('Dt ($\mu m^ 2$)')

grid('on')

#
def init():
    im1.set_data(XYslice[0,:,:])

    im2.set_data(XZslice[0,:,:])
    return([im1,im2])

def animate(t):
    im1.set_data(XYslice[t,:,:])
    im2.set_data(XZslice[t,:,:])
    return [im1,im2]

ani = animation.FuncAnimation(fig, animate, np.arange(len(Dt)),interval=250,
                              blit=True,init_func=init,repeat=True)

show()    

Tags: fromimportdatadtfigiididz

热门问题