Skip to content

Commit

Permalink
Add bokeh plots and deprecate contributions_pie (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulcollenteur committed Apr 4, 2024
2 parents d153578 + efe9f9a commit eb9013f
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
"source": [
"# Interactive plots \n",
"\n",
"*D.A. Brakenhoff (Artesia Water 2023)*\n",
"*D.A. Brakenhoff (Artesia Water 2023) and R.A. Collenteur (Eawag, 2024)*\n",
"\n",
"This notebook shows how interactive plots can be created using the Plotly extension.\n",
"\n",
"Extensions can be used to add functionality to existing classes in Pastas. In this\n",
"example the plotly extension is registered to the `pastas.Model` class, allowing us to\n",
"This notebook shows how interactive plots can be created using the [Plotly](https://plotly.com) and [Bokeh](https://docs.bokeh.org/en/latest/index.html) extensions. Extensions can be used to add functionality to existing classes in Pastas. In this example the plotly extension is registered to the `pastas.Model` class, allowing us to\n",
"create interactive figures."
]
},
Expand All @@ -22,17 +19,21 @@
"outputs": [],
"source": [
"# import the requisite packages\n",
"\n",
"import pandas as pd\n",
"import pastas as ps\n",
"\n",
"# To show bokeh plots inline in a jupyter notebook\n",
"from bokeh.io import output_notebook\n",
"output_notebook()\n",
"\n",
"ps.set_log_level(\"ERROR\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a Pastas model\n",
"Read in the heads, precipitation and evaporation data from the first example notebook."
]
},
Expand All @@ -45,7 +46,6 @@
"# read observations and create the time series model\n",
"obs = pd.read_csv(\"data/head_nb1.csv\", index_col=0, parse_dates=True).squeeze(\"columns\")\n",
"\n",
"\n",
"# read weather data\n",
"rain = pd.read_csv(\"data/rain_nb1.csv\", index_col=0, parse_dates=True).squeeze(\n",
" \"columns\"\n",
Expand Down Expand Up @@ -84,6 +84,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Making plotly plots\n",
"In order to add the interactive plotting extension to the `pastas.Model` class, we need\n",
"to register the extension. The Plotly extension is already part of the pastas plotting\n",
"library, but since it requires the `plotly` package as an optional dependency, it is\n",
Expand Down Expand Up @@ -187,6 +188,50 @@
"fig = ml.plotly.diagnostics()\n",
"fig.update_layout(height=800, width=800)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Making Bokeh plots\n",
"\n",
"Using Bokeh plots works similar to Plotly plots. First we register the Bokeh extension, which requires Bokeh to be installed. Also, make sure to run `output_notebook` (see top of this notebook) to show the figures inline in a Jupyter Notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# register plotly extension, requires bokeh to be installed\n",
"ps.extensions.register_bokeh()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ml.bokeh.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The results plot is available from `ml.bokeh.results` as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ml.bokeh.results(height=350)"
]
}
],
"metadata": {
Expand All @@ -202,7 +247,7 @@
},
"anaconda-cloud": {},
"kernelspec": {
"display_name": "pastas_dev",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand Down
2 changes: 1 addition & 1 deletion pastas/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def PastasDeprecationWarning(function: Function) -> Function:
@wraps(function)
def _function(*args, **kwargs):
logger.warning(
"Method is deprecated and will be removed in Pastas version 1.2."
"Method is deprecated since 1.5 and will be removed in Pastas version 1.6"
)
return function(*args, **kwargs)

Expand Down
7 changes: 7 additions & 0 deletions pastas/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ def register_plotly():
from pastas.plotting.plotly import Plotly

logger.info("Registered plotly extension in Model class, e.g. `ml.plotly.plot()`.")


def register_bokeh():
"""Register Bokeh extension for pastas.Model class for interactive plotting."""
from pastas.plotting.bokeh import Bokeh

logger.info("Registered bokeh extension in Model class, e.g. `ml.bokeh.plot()`.")
2 changes: 1 addition & 1 deletion pastas/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ def get_output_series(
for contrib in contribs:
df.append(contrib)

df = concat(df, axis=1)
df = concat(df, axis=1, sort=True)
return df

def _get_response(
Expand Down
5 changes: 3 additions & 2 deletions pastas/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
:nosignatures:
plots
modelplots
modelplots.Plotting
plotly.Plotly
bokeh.Bokeh
modelcompare
plotutil
plotly
"""

0 comments on commit eb9013f

Please sign in to comment.