3

雲を表示するimshowプロットと、雲の動きベクトルを表示する重ね合わせた矢筒プロットがあります。このプロットはピクセル単位で表示されていますが、クラウドシーンのサイズであるキロメートル単位で表示したいと思います。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()

これを説明するために、次の図を示します。 ここに画像の説明を入力してください

4

1 に答える 1

2

これを行うには2つの方法があります。矢筒の(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は次のようになります。

q = ax.quiver(..)
im = ax.imshow(...) # exactly like you had before
ax.get_xaxis().set_major_formatter(
    matplotlib.ticker.FuncFormatter(
        lambda x,i: '%.2f' % (x * km_per_pixel + km_offset_x)))
ax.get_yaxis().set_major_formatter(
    matplotlib.ticker.FuncFormatter(
        lambda x,i: '%.2f' % (x * km_per_pixel + km_ofset_y)))

フォーマット文字列を好きなように微調整する必要があります。ティックがsを調べる場所をより細かく制御したい場合Locator。(これらすべてのクラスのドキュメントはここにあります)

于 2012-12-24T17:07:48.353 に答える