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

Hvplot (timeseries) #198

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4c78ddf
bokeh_theme yaml similar to ouranos matplotlib stylesheet
sarahclaude Mar 6, 2024
c4f5245
update bijeh, env, __init__
sarahclaude Mar 22, 2024
9730f94
Merge branch 'main' into hvplot
sarahclaude Apr 18, 2024
29eaa7e
timseries fucntion in hvplot
sarahclaude Apr 26, 2024
bddedb4
Merge branch 'main' into hvplot
sarahclaude Apr 26, 2024
f189f5a
Added set style function, added hvplot to __init__
sarahclaude Apr 30, 2024
2e6c0af
Merge branch 'main' into hvplot
sarahclaude Apr 30, 2024
0fbcebc
fix bugs
sarahclaude Apr 30, 2024
1a0291c
fix bug ens_perc
sarahclaude May 1, 2024
0c837ed
fix bug ens_stat
sarahclaude May 1, 2024
ebe36a9
fix formatters and hover
sarahclaude May 2, 2024
bba460c
fix cplot_kw and hooks for hover area
sarahclaude May 14, 2024
8cb116b
fix bug
sarahclaude May 17, 2024
bf038e0
merge main and moved hvplot to src/figanos
sarahclaude May 21, 2024
c449628
fix curve_hover_hook (loop with hover_tools instead of hover)
sarahclaude May 22, 2024
9f26871
fix curve_hover_hook and added curve_hover_tool as other option
sarahclaude Aug 1, 2024
59ac7a1
added show_lat_lon to timeseries
sarahclaude Aug 5, 2024
8be59e7
Merge branch 'main' into hvplot
sarahclaude Aug 7, 2024
39896a8
added legend inplot to timeseries and notebook examples
sarahclaude Aug 23, 2024
41ab7de
small fix
sarahclaude Aug 23, 2024
0d9d2be
small fixes
sarahclaude Aug 23, 2024
7788ec2
missing packages
sarahclaude Aug 23, 2024
a4bf510
Merge branch 'main' into hvplot
Zeitsperre Sep 17, 2024
d8935d7
fix errors
sarahclaude Sep 25, 2024
973ac5d
fix errors
sarahclaude Sep 25, 2024
6254f1d
update pyproject.toml
sarahclaude Sep 25, 2024
c956d60
fix error tox
sarahclaude Sep 25, 2024
bff8648
fix error tox Union
sarahclaude Sep 25, 2024
80e91ad
fix error tox Union
sarahclaude Sep 25, 2024
150b8a4
fix error tox Union
sarahclaude Sep 25, 2024
a9837b8
fix error tox Union
sarahclaude Sep 25, 2024
f6c3e52
add to notebooks
sarahclaude Oct 1, 2024
055c411
Merge branch 'main' into hvplot
sarahclaude Oct 1, 2024
8cc6ad2
Merge branch 'main' into hvplot
sarahclaude Oct 4, 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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Marco Bra

New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* `figanos` now has timeseries available in the hvplot plotting library (:pull:`198`).
* `figanos` now supports Python 3.12. (:pull:`210`).
* Use list or ndarray as levels for colorbar in gridmap and small bug fixes (:pull:`176`).
* Added style sheet ``transparent.mplstyle`` (:issue:`183`, :pull:`185`)
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Need help?
notebooks/figanos_docs
notebooks/figanos_colours
notebooks/figanos_multiplots
notebooks/figanos_hvplot
api
contributing
releasing
Expand Down
194 changes: 194 additions & 0 deletions docs/notebooks/figanos_hvplot.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{
Copy link
Contributor

@juliettelavoie juliettelavoie Oct 2, 2024

Choose a reason for hiding this comment

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

Line #10.                                          #'group', 

clean up the commented line


Reply via ReviewNB

Copy link
Contributor

@juliettelavoie juliettelavoie Oct 2, 2024

Choose a reason for hiding this comment

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

Line #1.    from figanos.hvplot import timeseries

suggestion: au top mettre import figanos.hvplot as fgh et import figanos.matplotlig as fgm et ensuite faire fgh.timeseries et fgm.timeseries pour montrer que le call est presque pareil.


Reply via ReviewNB

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bonne idée! Seulement dans la doc hvplot ou toutes les docs?

Copy link
Contributor

Choose a reason for hiding this comment

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

je dirais juste hvplot

Copy link
Contributor

@juliettelavoie juliettelavoie Oct 2, 2024

Choose a reason for hiding this comment

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

Line #1.    timeseries(data2, legend='in_plot', show_lat_lon='lower left')

pourquoi quand c'est in_plot la legend est "realisation:0", mais lines est seulement "0"


Reply via ReviewNB

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lines est fait automatiquement par hvplot; je n'ai pas modifier comment il créait les légendes. Alors, que in_plot j'ai ajouté la fonction et j'ai essayé de mettre les mêmes options que pour matplotlib, mais peut-être que c'est incohérent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Je pense que ce serait plus beau avec juste "0", sans le nom de la dimension. Il me semble qu'on ne voit jamais le nom de la dim dans matplolib ?

Copy link
Contributor

@juliettelavoie juliettelavoie Oct 2, 2024

Choose a reason for hiding this comment

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

Je mettrais chaque arg sur une ligne différente pour que ça soit plus facile à lire.


Reply via ReviewNB

"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"# Interactive plotting"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"Figanos can also be used with the [hvplot](https://hvplot.holoviz.org/) library, which provides a high-level plotting API built on HoloViews to produce interactive plots."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import xarray as xr\n",
"from xclim import ensembles\n",
"xr.set_options(keep_attrs=True)"
]
},
{
"cell_type": "markdown",
"id": "3",
"metadata": {},
"source": [
"## HvPlot ouranos theme "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"from figanos.hvplot.utils import set_hv_style\n",
"\n",
"set_hv_style('ouranos')"
]
},
{
"cell_type": "markdown",
"id": "5",
"metadata": {},
"source": [
"## Timeseries\n",
"\n",
"The main elements of a plot are dependent on four arguments, each accepting dictionaries:\n",
"\n",
"1. `data` : a dictionary containing the Xarray objects and their respective keys, used as labels on the plot.\n",
"2. `use_attrs`: a dictionary linking attributes from the Xarray object to plot text elements.\n",
"3. `plot_kw` : a dictionary using the same keys as `data` to pass arguments to the underlying plotting function, in this case [hvplot.line](https://hvplot.holoviz.org/reference/tabular/line.html).\n",
"4. `opts_kw`: a dictionary using the same keys as `data` plus overlay (to be passed to the combined elements of all `data` values) to pass to the underlying `.opts` [holoviz funciton](https://holoviews.org/user_guide/Customizing_Plots.html).\n",
"\n",
"When labels are passed in `data`, any 'label' argument passed in `plot_kw` will be ignored."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"# creates dataset\n",
"\n",
"time = pd.date_range(start='1960-01-01', end='2020-01-01', periods=10)\n",
"np.random.seed(1231)\n",
"dat_1 = np.random.rand(10) * 20\n",
"dat_2 = np.random.rand(10) * 20\n",
"dat_3 = np.random.rand(10) * 20\n",
"\n",
"dt = xr.Dataset(data_vars={'tas': (['realization', \n",
" #'group', \n",
" 'time'], \n",
" #np.array([[dat_1, dat_2], [dat_2, dat_3], [dat_3, dat_1]])\n",
" np.array([dat_1, dat_2, dat_3])\n",
" )\n",
" },\n",
" coords={'time': time, \n",
" 'lat': 41,\n",
" 'lon':-73, \n",
" #'group': ['a', 'b'], \n",
" 'realization': [0, 1, 2]},\n",
" )\n",
"dt.tas.attrs={'long_name': 'Randomly generated time-series',\n",
" 'standart_name': 'air_temp',\n",
" 'description': \"Synthetic time-series\",\n",
" 'units': 'degC',}\n",
" \n",
"data2 = dt+10\n",
"\n",
"perc = ensembles.ensemble_percentiles(dt, values=[25, 50, 75], split=False)\n",
"stat = ensembles.ensemble_mean_std_max_min(dt).drop_vars('tas_stdev')\n",
"perc2 = ensembles.ensemble_percentiles(data2, values=[10, 50, 90], split=False)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"from figanos.hvplot import timeseries\n",
"timeseries(data2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"timeseries(data2, legend='in_plot', show_lat_lon='lower left')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"timeseries({'rcp85': data2, 'rcp45': dt}, opts_kw={'overlay': {'legend_position': 'bottom_right', 'legend_cols': 2}}, show_lat_lon='lower left')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"outputs": [],
"source": [
"timeseries({'val1': data2, 'val2': dt}, plot_kw={'val1': {'color': 'yellow'}, 'val2': {'line_width': 5, 'color': 'teal'}}, opts_kw={'overlay': {'legend_position': 'right'}}, show_lat_lon='lower left')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11",
"metadata": {},
"outputs": [],
"source": [
"timeseries({'ssp245': perc, 'ssp585': perc2}, legend='full' , show_lat_lon=False, opts_kw={'overlay': {'legend_position': 'right'}})"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12",
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 6 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
- default
dependencies:
- python>=3.9,<3.13
# Don't forget to sync changes between environment.yml and pyproject.toml!
# Main
- cartopy >=0.23.0
- cairosvg
Expand All @@ -18,6 +19,11 @@ dependencies:
- scikit-image
- xarray
- xclim >=0.47
# for interactive figures
- hvplot
- holoviews
- geoviews
- bokeh
# To make the package and notebooks usable
- dask
- h5py
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ dependencies = [
"seaborn",
"scikit-image",
"xarray",
"xclim >=0.47"
"xclim >=0.47",
"hvplot",
"holoviews",
"geoviews",
"bokeh"
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/figanos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
__email__ = "bourdeau-goulet.sarah-claude@ouranos.ca"
__version__ = "0.3.1-dev.12"

from . import matplotlib
from . import hvplot, matplotlib
from ._data import data
from ._logo import Logos
4 changes: 4 additions & 0 deletions src/figanos/hvplot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Figanos hvplot plotting module."""

from .plot import timeseries
from .utils import get_hv_styles, set_hv_style
Loading