Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facetgrid (multiplots) #136

Merged
merged 32 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8230064
added facetgrid to gridmap and trying to make scattermap work for fac…
sarahclaude Nov 18, 2023
07595ab
fix access to colorbar
juliettelavoie Nov 20, 2023
41e471c
added suptitle to attributes (input/output of set_plot attrs now axis…
sarahclaude Nov 21, 2023
7cbc347
fig_kw passed to xr.plot with facetgrid
sarahclaude Nov 21, 2023
441bc17
add warning for missing fig_kw options with facetgrid
sarahclaude Nov 21, 2023
4eff488
scattermap corrected
sarahclaude Nov 30, 2023
41cf877
Added example for scattermap over gridmap, corrected use of xlim/ylim…
sarahclaude Dec 6, 2023
e41e6e8
suptitle options
sarahclaude Dec 6, 2023
4ecc29a
Merge branch 'main' into facetgrids
Zeitsperre Dec 11, 2023
9e47437
comment out unused import
Zeitsperre Dec 11, 2023
f09f641
Merge branch 'main' into facetgrids
sarahclaude Jan 4, 2024
55f99cb
show_time with facetgrids
sarahclaude Jan 5, 2024
148d9fc
Merge branch 'main' into facetgrids
sarahclaude Jan 5, 2024
9884fcc
Added facetgrids to hatchmap and corrected docs example
sarahclaude Jan 16, 2024
51492bd
Merge branch 'main' into facetgrids
sarahclaude Jan 16, 2024
a52eeb1
Xarray bug + figsizes examples in multiplots docs
sarahclaude Jan 16, 2024
e3123c5
edgecolors to edgecolor, docs
sarahclaude Jan 17, 2024
8bb7f0c
inconsistency between fig_kw and subplots_kw
sarahclaude Jan 18, 2024
ac31c00
Revert "inconsistency between fig_kw and subplots_kw"
sarahclaude Jan 23, 2024
3629618
corrected subplots and added row + col example
sarahclaude Jan 25, 2024
b6c7da4
index + changes .rst
sarahclaude Jan 25, 2024
1c37ac5
docs changes
sarahclaude Jan 29, 2024
68eb264
Merge branch 'main' into facetgrids
sarahclaude Feb 1, 2024
a09d974
Merge branch 'main' into facetgrids
juliettelavoie Feb 2, 2024
eb564ae
Merge branch 'main' into facetgrids
juliettelavoie Feb 5, 2024
28d7cb2
env req
juliettelavoie Feb 5, 2024
13fcf4a
i was in the wrong branch sorry
juliettelavoie Feb 5, 2024
e4a45d8
correct commits, .squeeze() dataarray
sarahclaude Feb 15, 2024
270bb67
Merge remote-tracking branch 'origin/facetgrids' into facetgrids
sarahclaude Feb 15, 2024
0be84b3
Merge branch 'main' into facetgrids
sarahclaude Feb 15, 2024
1311e6e
tas exemples for hatchmap
sarahclaude Feb 15, 2024
6bd521d
changed title
sarahclaude Feb 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions docs/notebooks/figanos_multiplots.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
sarahclaude marked this conversation as resolved.
Show resolved Hide resolved
sarahclaude marked this conversation as resolved.
Show resolved Hide resolved
sarahclaude marked this conversation as resolved.
Show resolved Hide resolved
sarahclaude marked this conversation as resolved.
Show resolved Hide resolved
sarahclaude marked this conversation as resolved.
Show resolved Hide resolved
sarahclaude marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

@juliettelavoie juliettelavoie Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comme il n'y a pas d'exemple ici, je l'enleverrais ou j'écrirais "Section coming soon".


Reply via ReviewNB

Copy link
Contributor

@juliettelavoie juliettelavoie Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juste une question d'esthétique. J'ajouterais        legend_kw={'ncol':4,'bbox_to_anchor':(0.15, 0.05)


Reply via ReviewNB

Copy link
Contributor

@juliettelavoie juliettelavoie Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avec xclim 0.47, cette cellule brise parce que change_significance a une nouvelle signature.

https://xclim.readthedocs.io/en/stable/changes.html

change_significance va m[eme disparaitre à 0.49. but this can be fixed in another PR.


Reply via ReviewNB

Copy link
Contributor

@juliettelavoie juliettelavoie Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might change this to just " Multiple Plots"


Reply via ReviewNB

"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Figanos multiple plots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create subplots and facetgrids with Figanos."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import necessary libraries\n",
"import xarray as xr\n",
"import cartopy.crs as ccrs\n",
"import figanos.matplotlib as fg\n",
"import numpy as np\n",
"\n",
"# use ouranos style\n",
"fg.utils.set_mpl_style('ouranos')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# create xarray object from a NetCDF\n",
"url = 'https://pavics.ouranos.ca//twitcher/ows/proxy/thredds/dodsC/birdhouse/disk2/cccs_portal/indices/Final/BCCAQv2_CMIP6/tx_max/YS/ssp585/ensemble_percentiles/tx_max_ann_BCCAQ2v2+ANUSPLIN300_historical+ssp585_1950-2100_30ymean_percentiles.nc'\n",
"opened = xr.open_dataset(url, decode_timedelta=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Timeseries\n",
"Create multiple timeseries plot with matplotlib subplots and figanos as shown below."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Maps\n",
"Create multiple maps plot with figanos wrapped around xr.plot.facetgrid.FacetGrid by passing the arguement row and/or col in plot_kw."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Selecting a time and slicing our starting Dataset\n",
"ds_space = opened[['tx_max_p50']].isel(time=[0, 1, 2]).sel(lat=slice(40,65), lon=slice(-90,-55))\n",
"\n",
"# defining our projection.\n",
"projection = ccrs.LambertConformal()\n",
"\n",
"im = fg.gridmap(ds_space, projection = projection, plot_kw = {\"x\": \"lon\", \"y\": \"lat\", \"col\": \"time\"}, features = ['coastline','ocean'], frame = False, use_attrs={\"suptitle\": \"description\"})\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"names = ['station_' + str(i) for i in np.arange(5)]\n",
"lat = 45 + np.random.rand(5)*3\n",
"lon = np.linspace(-76,-70, 5)\n",
"tas = np.array([[20, 25, 30, 15, 5], [5, 0, 10, 2, 3]])\n",
"yrs = np.array([[35, 65, 45, 25, 95],\n",
" [15, 75, 10, 15, 50]])\n",
"\n",
"attrs = {'units': 'degC', 'standard_name': 'air_temperature', 'long_name': 'Near-Surface Daily Maximum Air Temperature'}\n",
"\n",
"tas = xr.DataArray(data=tas,\n",
" coords={'season': ['DFJ', 'MAM'],\n",
" 'station': names,\n",
" 'lat':('station', lat),\n",
" 'lon': ('station', lon),\n",
" 'years': (('season', 'station'), yrs),\n",
" },\n",
" dims=['season', 'station'],\n",
" attrs=attrs)\n",
"obs = xr.Dataset({'tas': tas})\n",
"\n",
"# plot\n",
"fg.scattermap(obs,\n",
" transform=ccrs.PlateCarree(),\n",
" sizes='years',\n",
" size_range=(25, 100),\n",
" plot_kw={\n",
" \"xlim\": (-77,-69),\n",
" \"ylim\":(43,50),\n",
" \"col\": \"season\",\n",
" },\n",
" features={\n",
" \"land\": {\"color\": \"#f0f0f0\"},\n",
" \"rivers\": {\"edgecolor\": \"#cfd3d4\"},\n",
" \"lakes\": {\"facecolor\": \"#cfd3d4\"},\n",
" \"coastline\": {\"edgecolor\": \"black\"},\n",
" }\n",
" )\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot over each other"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"names = ['station_' + str(i) for i in np.arange(5)]\n",
"lat = 45 + np.random.rand(5)*3\n",
"lon = np.linspace(-76,-70, 5)\n",
"tas = np.array([[290, 300, 295, 305, 301], [275, 285, 277, 301, 345], [302, 293, 295, 292, 280]])\n",
"\n",
"attrs = {'units': 'degK', 'standard_name': 'air_temperature', 'long_name': ds_space.tx_max_p50.attrs['description']}\n",
"\n",
"tas = xr.DataArray(data=tas,\n",
" coords={'time': ds_space.time.values,\n",
" 'station': names,\n",
" 'lat':('station', lat),\n",
" 'lon': ('station', lon),\n",
" },\n",
" dims=['time', 'station'],\n",
" attrs=attrs)\n",
"obs2 = xr.Dataset({'tas': tas})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vmin=280\n",
"vmax=310\n",
"\n",
"im = fg.gridmap(ds_space,\n",
" projection = projection,\n",
" plot_kw = {\"col\": \"time\",\n",
" \"xlim\": (-77,-69), \"ylim\": (43,50),\n",
" \"vmin\": vmin, \"vmax\": vmax,\n",
" },\n",
" features = ['coastline','ocean'],\n",
" frame = False,\n",
" use_attrs={\"suptitle\": \"description\"}\n",
" )\n",
"for i, fax in enumerate(im.axs.flat):\n",
" fg.scattermap(obs2.isel(time=i),\n",
" ax=fax,\n",
" transform=ccrs.PlateCarree(),\n",
" plot_kw={'vmin': vmin, 'vmax': vmax, 'edgecolors':'grey', 'add_colorbar': False}\n",
" )\n",
"im.fig.suptitle('Scattermaps over gridmaps', x=0.45, y=0.95)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading