I am trying to use the simple .plot() function from xarray on a netCDF file from the atmospheric composition analysis group.
Say I want to plot the PM2.5 concentration from North America in 2000 available here.
When I try to plot the dataset I get an empty figure even though the data exists as shown by the legend bar.
import xarray as xr
import netCDF4 as nc
import matplotlib.pyplot as plt
path_to_nc="my/path/file.nc"
ds=xr.open_dataset(path_to_nc)
print(ds)
>>>
<xarray.Dataset>
Dimensions: (LAT: 4550, LON: 9300)
Coordinates:
* LON (LON) float64 -138.0 -138.0 -138.0 -138.0 ... -45.03 -45.01 -45.01
* LAT (LAT) float64 68.0 67.99 67.97 67.96 ... 22.53 22.52 22.51 22.5
Data variables:
PM25 (LAT, LON) float32 ...
The file does have values (not just nan).
# Range of values:
ds=ds['PM25']
print(ds)
>>>
<xarray.DataArray 'PM25' (LAT: 4550, LON: 9300)>
array([[1.6, 1.6, 1.6, ..., 1.2, 1.2, 1.2],
[1.6, 1.6, 1.6, ..., 1.2, 1.2, 1.2],
[1.6, 1.6, 1.6, ..., 1.2, 1.2, 1.2],
...,
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan]], dtype=float32)
Coordinates:
* LON (LON) float64 -138.0 -138.0 -138.0 -138.0 ... -45.03 -45.01 -45.01
* LAT (LAT) float64 68.0 67.99 67.97 67.96 ... 22.53 22.52 22.51 22.5
Attributes:
standard_name: PM25
units: ug/m3
But if I try to plot the values then I get an empty ax.
ds.plot()