I made a pcolormesh-plot from data in NetCDF data format. I don't manage the x- and y-axis to show the right axis ticks from the data set. Instead both axis start from zero and end with the number of points. From the NetCDF desciption https://unidata.github.io/netcdf4-python/ I also do not get the point.
Any tip for me?
Here is what I did:
Packages I load:
import netCDF4 as nc
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm, SymLogNorm, Normalize
from pylab import cm as pylab_cm
from bokeh.plotting import figure, show, output_file, output_notebook, ColumnDataSource
from bokeh.io import output_notebook, export_png
from bokeh.models.tools import HoverTool, BoxZoomTool, ResetTool, SaveTool, WheelZoomTool, ZoomOutTool
from bokeh.models.tools import PanTool, UndoTool, RedoTool, BoxEditTool, FreehandDrawTool, PolyDrawTool, PolyEditTool
from bokeh.layouts import column, gridplot
from bokeh.models import Band, LinearAxis, Range1d, Label, LabelSet, Title
Data format of my (more-dimensional) variable is:
print(ds['raw'])
gives as result:
<class 'netCDF4._netCDF4.Variable'>
float32 raw(time, range)
units:
long_name: normalized range corrected signal
unlimited dimensions: time
current shape = (5760, 1024)
filling on, default _FillValue of 9.969209968386869e+36 used
I load the data set and transpose it as I want the time stamp on the x-axis:
nrcs = ds['raw'][:]
nrcs = nrcs.transpose()
This should -due to 'float32 raw(time, range)- already contain the time information, right?
I reformat the time stamp:
dtime = nc.num2date(ds['time'][:], ds['time'].units)
Then I create my plot:
fig1 = plt.figure(figsize=(14,8))
ax = fig1.add_subplot(1,1,1)
im = ax.pcolormesh(nrcs, norm=Normalize(vmin=t[8], vmax=t[11], clip=False), cmap=pylab_cm.viridis_r, shading='gouraud')
# I tried this but it does not work:
#ax.xaxis_date()
#ax.xaxis.set_major_formatter(mdates.DateFormatter('%H %M'))
ax.set_xlabel(r'Time / hh:mm:ss', fontsize=10)
ax.set_ylabel(r'Altitude', fontsize=10)
And the result looks like this:
In real, the altitude data on the y-axis is from 0...to above 10 000 m and the x-axis should be a time format. Any hint how I can bring the matlibplot to read the right dimensions?
Thanks in advance.