我对Python比较陌生,更熟悉Matlab。 我正在尝试制作一系列2 x 5的等高线子图。到目前为止,我的方法是将我的Matlab代码转换为Python,并在循环中绘制我的子图。相关代码如下:
fig=plt.figure(figsize=(15, 6),facecolor='w', edgecolor='k')
for i in range(10):
#this part is just arranging the data for contourf
ind2 = py.find(zz==i+1)
sfr_mass_mat = np.reshape(sfr_mass[ind2],(pixmax_x,pixmax_y))
sfr_mass_sub = sfr_mass[ind2]
zi = griddata(massloclist, sfrloclist, sfr_mass_sub,xi,yi,interp='nn')
temp = 250+i # this is to index the position of the subplot
ax=plt.subplot(temp)
ax.contourf(xi,yi,zi,5,cmap=plt.cm.Oranges)
plt.subplots_adjust(hspace = .5,wspace=.001)
#just annotating where each contour plot is being placed
ax.set_title(str(temp))
作为这个论坛的新手,我似乎无法附加结果图片。然而,根据我的代码中的索引“temp”,2 x 5 面板的布局如下:251 - 252 - 253 - 254 - 255
256 - 257 - 258 - 259 - 250
然而,我想要的是
250 - 251 - 252 - 253 - 254
255 - 256 - 257 - 258 - 259
也就是说,第一个面板(250)出现在我认为应该是259的最后位置。而251似乎是我想要放置250的地方。它们所有的顺序都正确,只是循环移位了一个位置。
我知道这一定是一些非常愚蠢的问题,但感激您所能提供的任何帮助。
提前感谢您。
axs = axs.ravel()
在这里的妙处在于它能够将数组扁平化。 - seralouk