1

I have to plot the 2D array (called para_beta) with dimensions (2779, 1334). These dimensions refer to the (time, height) that the measurements were taken.

When I plot using the code, the x axis and y axis ticks are just the count of the array dimensions, and don't reflect the time or height. I have lists of time_hour (len = 2779) and altitude (len = 1334) which give the actual time and height and need to be the x and y axis values. How do I do this?

#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()

I have tried using extent and using ax1.set_xticklabels(time_hour) but these don't work. I included the resulting figure from the above code - if it was correct the x axis should extend to 24, and the y axis to 20.

enter image description here

Jess Brown
  • 107
  • 11

2 Answers2

1

para_beta is 2D (time x height), right? Then the read-in call needs to reflect those two dimensions:

para_beta_raw = nc_file.variables['para_beta'][:,:] (note the two colons, instead of one).

N1B4
  • 3,377
  • 1
  • 21
  • 24
0

I just found a duplicate of my question which has already been answered! I was using extent wrong as I took the min/max values from the para_beta array, when they should be taken from the time_bnds and altitude array:

#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()
Community
  • 1
  • 1
Jess Brown
  • 107
  • 11