如何使用pcolor将向量设置为y轴

问题描述 投票:0回答:1

我想用pcolor设置y轴,例如y轴是深度。在此示例中,我想将向量z设置为y轴,该怎么做?这是我的代码:

from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.colors import LogNorm
from matplotlib.ticker import LogLocator
z=np.arange(1,90,2)
mrectest = np.random.rand(45, 15)
fig, ax = plt.subplots(figsize=(20,20))
divider = make_axes_locatable(ax)
cax = divider.append_axes('right', size='5%', pad=0.1)

im = ax.pcolor(mrectest,vmin = 0.1, vmax = 800, norm = LogNorm(),cmap= 'jet')
cbar = fig.colorbar(im,cax=cax, orientation='vertical')
cbar.ax.yaxis.set_major_locator(LogLocator())  # <- Why? See above.
#ax.invert_yaxis()
#cbar.set_ticks(cbar.ax.yaxis.get_major_locator().tick_values(0.01, 1000))
plt.savefig('mrec_exp_28_02'+'.png',bbox_inches = "tight", format='png', dpi=1000)  
plt.show()
python matplotlib plot imshow yaxis
1个回答
0
投票

我按照评论中的解释得到它。

© www.soinside.com 2019 - 2024. All rights reserved.