Skip to content

Commit

Permalink
Merge pull request #265 from Ouranosinc/triheatmap
Browse files Browse the repository at this point in the history
triheatmap
  • Loading branch information
juliettelavoie authored Oct 3, 2024
2 parents a4cec16 + 5ab2f08 commit 7126686
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ New features and enhancements
* ``fg.taylordiagram`` can now accept datasets with many dimensions (not only `taylor_params`), provided that they all share the same `ref_std` (e.g. normalized taylor diagrams) (:pull:`214`).
* A new optional way to organize points in a ``fg.taylordiagram`` with `colors_key`, `markers_key` : DataArrays with a common dimension value or a common attribute are grouped with the same color/marker (:pull:`214`).
* Heatmap (``fg.matplotlib.heatmap``) now supports `row,col` arguments in `plot_kw`, allowing to plot a grid of heatmaps. (:issue:`208`, :pull:`219`).
* New function ``fg.matplotlib.triheatmap`` (:pull:`199`).

Breaking changes
^^^^^^^^^^^^^^^^
Expand Down
79 changes: 70 additions & 9 deletions docs/notebooks/figanos_docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,67 @@
"cell_type": "markdown",
"id": "61",
"metadata": {},
"source": [
"## Triangle heatmaps\n",
"\n",
"The `triheatmap` function is based on the matplotlib function [tripcolor](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tripcolor.html). It can create a heatmap with 2 or 4 triangles in each square of the heatmap.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62",
"metadata": {},
"outputs": [],
"source": [
"# Create a fake data\n",
"da = xr.DataArray(data=np.random.rand(2,3,4),\n",
" coords=dict(realization=['A', 'B'],\n",
" method=['a','b', 'c'],\n",
" experiment=['ssp126','ssp245','ssp370','ssp585'],\n",
" ))\n",
"da.name='pr' # to guess the cmap\n",
"# will be automatically detected for the cbar label\n",
"da.attrs['long_name']= 'precipitation' \n",
"da.attrs['units']= 'mm'\n",
"\n",
"# Plot a heatmap\n",
"fg.triheatmap(da,\n",
" z='experiment', # which dimension should be represented by triangles\n",
" divergent=True, # for the cmap\n",
" cbar='unique', # only show one cbar\n",
" plot_kw={'vmin':-1, 'vmax':1} # we are only showing the 1st cbar, so make sure the cbar of each triangle is the same\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63",
"metadata": {},
"outputs": [],
"source": [
"# Create a fake data\n",
"da = xr.DataArray(data=np.random.rand(4,3,2),\n",
" coords=dict(realization=['A', 'B', 'C','D'],\n",
" method=['a','b', 'c'],\n",
" season=['DJF','JJA'],\n",
" ))\n",
"da.attrs['description']= \"La plus belle saison de ma vie\"\n",
"\n",
"# Plot a heatmap\n",
"fg.triheatmap(da,\n",
" z='season',\n",
" cbar='each', # show a cbar per triangle\n",
" use_attrs={'title':'description'},\n",
" cbar_kw=[{'label':'winter'},{'label':'summer'}], # Use a list to change the cbar associated with each triangle type (upper or lower)\n",
" plot_kw=[{'cmap':'winter'},{'cmap':'summer'}]) # Use a list to change each triangle type (upper or lower)"
]
},
{
"cell_type": "markdown",
"id": "64",
"metadata": {},
"source": [
"## Taylor Diagrams\n",
"\n",
Expand All @@ -1006,7 +1067,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "62",
"id": "65",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1025,7 +1086,7 @@
},
{
"cell_type": "markdown",
"id": "63",
"id": "66",
"metadata": {},
"source": [
"### Normalized taylor diagram\n",
Expand All @@ -1036,7 +1097,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "64",
"id": "67",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1070,7 +1131,7 @@
},
{
"cell_type": "markdown",
"id": "65",
"id": "68",
"metadata": {},
"source": [
"## Partition plots\n",
Expand All @@ -1090,7 +1151,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "66",
"id": "69",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1138,7 +1199,7 @@
},
{
"cell_type": "markdown",
"id": "67",
"id": "70",
"metadata": {},
"source": [
"Compute uncertainties with xclim and use `fractional_uncertainty` to have the right format to plot."
Expand All @@ -1147,7 +1208,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "68",
"id": "71",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1182,7 +1243,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "69",
"id": "72",
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -1212,7 +1273,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.12.0"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions src/figanos/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
stripes,
taylordiagram,
timeseries,
triheatmap,
violin,
)
from .utils import categorical_colors, plot_logo, set_mpl_style
Loading

0 comments on commit 7126686

Please sign in to comment.