matplotlib在quiver p中的变化幅度

2024-10-01 07:44:50 发布

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

我有一个图像显示图,显示云,和一个叠加的震动图,显示云的运动矢量。这个图现在以像素为单位显示,但我想用公里来显示,这是云层场景的大小。我可以在imshow中改变范围,但比颤抖图更不适合了。在

你有什么建议吗?任何帮助都将不胜感激!在

圣诞快乐

这是我的代码:

# size I want to be shown in the plot (in kilometer)
size = 9.750

# -> extent[0, size, 0, size]


# arrays used in plot (pixel size)

im_current = np.array((275,275))  
xdis_mean = np.array((275,275))
ydis_mean = np.array((275,275))


# settings for the quiver plot

sliceNr=20  # every x pixel will be shown
sy,sx =np.shape(im_current) 
x=np.arange(sx)[::sliceNr]
y=np.arange(sy)[::sliceNr]


# colormap for the quiver plot
M = sqrt(pow(xdis_mean[::sliceNr,::sliceNr], 2) + pow(ydis_mean[::sliceNr,::sliceNr], 2))



fig=plt.figure()

ax=fig.add_subplot(111)
cax=ax.imshow(im_current,origin='lower', cmap=cmap,vmin=0,vmax=1,norm=norm)

setp(plt.Axes.get_xticklabels(plt.gca()), fontsize=10)
setp(plt.Axes.get_yticklabels(plt.gca()), fontsize=10)


title('image at t=0 \n with mean displacement vector field')

xlabel('area size [pixel]',fontsize=9)
ylabel('area size [pixel]',fontsize=9)

# get axes from subplot to adjust colorbar to these axes
divider = make_axes_locatable(plt.gca())
cax1 = divider.append_axes("right", "5%", pad="4%")

cbar1=plt.colorbar(cax,cax=cax1,cmap=cmap,boundaries=bounds,ticks=[0,1],use_gridspec=True)
cbar1.ax.set_yticklabels(['0','1'],fontsize=10)


v=ax.quiver(x,y,xdis_mean[::sliceNr,::sliceNr],ydis_mean[::sliceNr,::sliceNr],M, units='xy',angles='xy',scale=1,scale_units='xy',cmap='autumn')

cax2 = divider.append_axes("bottom", "5%", pad="9%")
cbar2=plt.colorbar(v,cax=cax2,orientation='horizontal',use_gridspec=True)
for t in cbar2.ax.get_xticklabels():
    t.set_fontsize(10)

plt.tight_layout()

show()

为了说明这一点,下图: enter image description here


Tags: toinsizegetplotnppltax
1条回答
网友
1楼 · 发布于 2024-10-01 07:44:50

有两种方法可以做到这一点:您可以重新缩放箭筒的(x,y)数据,也可以设置标签格式化程序。在

选项A是这样的:

x,y = x*km_per_pixel + km_offset_x, y*km_per_pixel + km_offset_y
im = ax.imshow(...,exent=lims_in_km)
q = ax.quiver(x,y,...)

选项B是这样的:

^{pr2}$

您应该调整格式化字符串,使之成为您喜欢的格式。如果您希望对有更多的控制,那么记号将被查找到Locators(所有这些类的文档都在here

相关问题 更多 >