I am trying something like this:
import xarray as xr
import numpy as np
(lon,lat)=np.meshgrid(np.arange(0,6,1),np.arange(0,6,1))
da_data=xr.DataArray(data=np.random.randn(6,6),dims=['y','x'],
coords=dict(LAT=(['y','x'],lat), LON=(['y','x'],lon)) )
da_data.plot.contour(kwargs=dict(inline=True))
I can see the contours but no labels. What am I doing wrong?
CodePudding user response:
Check the istruction to use metadata in labels:
xarray.plot.contour(darray, x, y, **kwargs)
add_labels (bool, optional) – Use xarray metadata to label axes.
Check the parameters: https://xarray.pydata.org/en/stable/generated/xarray.plot.contour.html
CodePudding user response:
xarray.plot
uses matplotlib as a backend, and you can replace your last line with the following, using matplotlib's Axis.clabel
fig, ax = plt.subplots()
CS = da_data.plot.contour(kwargs=dict(inline=True), ax=ax)
ax.clabel(CS)
See the matplotlib.contour.ContourLabeler.clabel
documentation and the countour label demo for more info.