2016-05-31 71 views
0

我必须绘制尺寸为(2779,1334)的二维数组(称为para_beta)。这些尺寸指的是测量结果的(时间,高度)。使用imshow绘制二维数组,设置坐标轴值

当我使用代码绘图时,x轴和y轴刻度只是数组维数,并不反映时间或高度。 我有time_hour(len = 2779)和高度(len = 1334)的列表,它给出了实际的时间和高度,并且需要是x和y轴的值。我该怎么做呢?

#Importing variables (from netcdf file) 
para_beta_raw = nc_file.variables['para_beta'][:] #Dim = time, height 
para_beta  = np.swapaxes(para_beta,0,1) # swap axes to put time on x axis 
time_hour  = time_bnds.tolist() 
altitude  = height_raw.tolist()  

fig = plt.figure('Parallel') 
ax1 = fig.add_subplot(111) 
im = ax1.imshow(para_beta1, aspect = 'auto', cmap = 'jet', interpolation = 'none', origin = 'lowest') 
cb = plt.colorbar(im, label = 'Parallel ATB [$m^{-1}\,sr^{-1}$]') 
cb.set_clim([0.0001, 1.0]) 
ax1.set_xlabel('Time (Decimal hours)') 
ax1.set_ylabel('Height (km)') 
plt.show() 

我一直在使用extent和使用ax1.set_xticklabels(time_hour)尝试,但这些不工作。我包括从上面的代码所产生的数字 - 如果它是正确的x轴应扩大到24,并且y轴为20。

enter image description here

回答

1

para_beta是2D(时间x高),是吗?然后阅读呼叫需要反映这两个维度:

para_beta_raw = nc_file.variables['para_beta'][:,:](注意两个冒号,而不是一个)。

0

我刚刚发现了一个已经被回答的duplicate of my question!我正在使用extent错误,因为我从para_beta阵列中获取了最小值/最大值,这些值应该从time_bnds和高度数组中获取:

#Importing variables (from netcdf file) 
para_beta_raw = nc_file.variables['para_beta'][:,:] #Dim = time, height 
para_beta  = np.swapaxes(para_beta,0,1) # swap axes to put time on x axis 
time_hour  = time_bnds.tolist() 
altitude  = height_raw.tolist()  

fig = plt.figure('Parallel') 
ax1 = fig.add_subplot(111) 
im = ax1.imshow(para_beta1, extent =(time_bnds.min(), time_bnds.max(), altitude.min(), altitude.max()), aspect = 'auto', cmap = 'jet', interpolation = 'none', origin = 'lowest') 
cb = plt.colorbar(im, label = 'Parallel ATB [$m^{-1}\,sr^{-1}$]') 
cb.set_clim([0.0001, 1.0]) 
ax1.set_xlabel('Time (Decimal hours)') 
ax1.set_ylabel('Height (km)') 
plt.show()