Skip to content
Snippets Groups Projects
Commit 4c0b6c0c authored by Aaron Spring's avatar Aaron Spring
Browse files

plot_map example facet

parent 8e16ab55
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# plotting MPI-ESM ocean # plotting MPI-ESM ocean
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%load_ext lab_black %load_ext lab_black
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import xarray as xr import xarray as xr
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
%matplotlib inline %matplotlib inline
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
p = "/work/mj0060/m300413/mpiesm-1.2.01p5/experiments/awi0069_cmor/archive/CMIP6/CMIP/MPI-M/MPI-ESM1-2-LR/esm-hist/r1i1p1f1/Omon/fgco2/gn/v20190710/fgco2_Omon_MPI-ESM1-2-LR_esm-hist_r1i1p1f1_gn_185001-186912.nc" p = "/work/mj0060/m300413/mpiesm-1.2.01p5/experiments/awi0069_cmor/archive/CMIP6/CMIP/MPI-M/MPI-ESM1-2-LR/esm-hist/r1i1p1f1/Omon/fgco2/gn/v20190710/fgco2_Omon_MPI-ESM1-2-LR_esm-hist_r1i1p1f1_gn_185001-186912.nc"
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
da = xr.open_dataset(p)["fgco2"].isel(time=3) da = xr.open_dataset(p)["fgco2"].isel(time=3)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
da.coords da.coords
``` ```
%% Output %% Output
Coordinates: Coordinates:
time datetime64[ns] 1850-04-16 time datetime64[ns] 1850-04-16
* j (j) int32 0 1 2 3 4 5 6 7 8 ... 212 213 214 215 216 217 218 219 * j (j) int32 0 1 2 3 4 5 6 7 8 ... 212 213 214 215 216 217 218 219
* i (i) int32 0 1 2 3 4 5 6 7 8 ... 248 249 250 251 252 253 254 255 * i (i) int32 0 1 2 3 4 5 6 7 8 ... 248 249 250 251 252 253 254 255
latitude (j, i) float64 ... latitude (j, i) float64 ...
longitude (j, i) float64 ... longitude (j, i) float64 ...
depth float64 ... depth float64 ...
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## xarray default ## xarray default
uses dimensions, here `i` and `j` uses dimensions, here `i` and `j`
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
da.plot(robust=True, yincrease=False) da.plot(robust=True, yincrease=False)
``` ```
%% Output %% Output
<matplotlib.collections.QuadMesh at 0x2b0b3cec2d50> <matplotlib.collections.QuadMesh at 0x2b0b3cec2d50>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## xarray with cartopy ## xarray with cartopy
understands coordinates, here `latitude` and `longitude` understands coordinates, here `latitude` and `longitude`
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import cartopy.crs as ccrs import cartopy.crs as ccrs
import cartopy import cartopy
ax = plt.axes(projection=ccrs.PlateCarree()) ax = plt.axes(projection=ccrs.PlateCarree())
da.plot(y="latitude", x="longitude", ax=ax, transform=ccrs.PlateCarree(), robust=True) da.plot(y="latitude", x="longitude", ax=ax, transform=ccrs.PlateCarree(), robust=True)
ax.set_global() ax.set_global()
ax.coastlines() ax.coastlines()
ax.add_feature(cartopy.feature.LAND) ax.add_feature(cartopy.feature.LAND)
``` ```
%% Output %% Output
<cartopy.mpl.feature_artist.FeatureArtist at 0x2b0b4781b310> <cartopy.mpl.feature_artist.FeatureArtist at 0x2b0b4781b310>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### pymistral.plot_map ### pymistral.plot_map
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import pymistral import pymistral
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
da.plot_map() da.plot_map()
``` ```
%% Output %% Output
<matplotlib.collections.QuadMesh at 0x2b0e942ba750> <matplotlib.collections.QuadMesh at 0x2b0e942ba750>
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
da.plot_map(feature='land',proj='Robinson') da.plot_map(feature='land',proj='Robinson')
``` ```
%% Output %% Output
<matplotlib.collections.QuadMesh at 0x2b0e943a9fd0> <matplotlib.collections.QuadMesh at 0x2b0e943a9fd0>
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
da = xr.open_dataset(p)["fgco2"].isel(time=[0,1,2])
``` ```
%% Cell type:code id: tags:
``` python
da.plot_map(col='time',proj='InterruptedGoodeHomolosine')
```
%% Output
<xarray.plot.facetgrid.FacetGrid at 0x2b0b3a244a90>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment