2016-05-31 73 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()