我对Python完全陌生,完全迷失了方向。 我的主管帮助我生成了一个脚本,以查看3D velocity模型的一些片段:
import numpy as np
import matplotlib.pyplot as plt
import yt
from yt.units import km
#Import et reshape data
d = np.genfromtxt('velocity_model.txt', delimiter=' ')
nd=22
nx=131
vel = d[:,3].reshape(nd,nx,nx)
lat = d[:,0].reshape(nd,nx,nx)
lon = d[:,1].reshape(nd,nx,nx)
dep = d[:,2].reshape(nd,nx,nx)
# When this is read into YT, depth increases along x axis, longitude increases along y axis and latitude increases along z axis, need to swap x and z and then flip z
dep=dep.swapaxes(0,2) # swap first and third dimensions: gives lon (x), lat (y), depth (z)
vel=vel.swapaxes(0,2) # swap first and third dimensions:
lat=lat.swapaxes(0,2) # swap first and third dimensions:
lon=lon.swapaxes(0,2) # swap first and third dimensions:
dep=dep[:,:,::-1] # reverse z direction
vel=vel[:,:,::-1] # swap first and 2nd dimensions:
lat=lat[:,:,::-1] # swap first and 2nd dimensions:
lon=lon[:,:,::-1] # swap first and 2nd dimensions:
xmin=0
xmax=289
ymin=0
ymax=289
zmin=-100
zmax=5
#Entrer dans YT
data=dict(velocity=(vel,'km/s'),latitude=(lat,'deg'),longitude=(lon,'deg'),depth=(dep,'km'))
bbox = np.array([[xmin,xmax], [ymin,ymax], [zmin,zmax]])
ds=yt.load_uniform_grid(data,vel.shape, length_unit='km', bbox=bbox)
#Off-Axis Slice
for key in ['latitude','longitude','depth','velocity'] :
L = [0,0,1] # cutting plane=z
slicepos=-50
c = [(xmax-xmin)/2, (ymax-ymin)/2, slicepos]
cut = yt.SlicePlot(ds, L, key,origin='native',center=c) #, width=(200,90,'km'))
cut.set_log(key, False)
cut.annotate_text([0.5,0.9],'z={:d} km'.format(slicepos),coord_system='axis')
cut.set_cmap(field='velocity',cmap='jet_r')
cut.save()
有了这个脚本,我想修复colorbar,因为对于每个图像,这一个都会发生变化,而且这样解释并不容易。在
我试着增加这样的限制:
^{pr2}$但这不是好办法。有人有主意吗?我看到了很多东西,但不是为了cmap。在
这实际上是一个关于yt visualization library而不是matplotlib本身的问题-我编辑了标题和标记来反映这一点。在
我以前从未遇到过yt,但根据^{} 的官方文档,似乎}对象。这两个类都有一个^{} 方法,它似乎可以执行您想要的操作:
cut
将是AxisAlignedSlicePlot
或{换句话说,您可以使用:
您正在寻找
set_zlim
函数:http://yt-project.org/doc/reference/api/generated/yt.visualization.plot_window.AxisAlignedSlicePlot.set_zlim.html
set_cmap
函数只允许您选择想要的颜色映射,它不允许您设置colormap范围。您需要使用set_zlim
来实现这一点。下面是一个示例,使用http://yt-project.org/data中的一个示例数据集:这将生成以下图像:
相关问题 更多 >
编程相关推荐