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

Extend and rerun tutorials #38

Merged
merged 6 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added docs/source/_static/ArviZ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/ArviZ_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/source/api/backend/index.part.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ Available backends
:link: matplotlib
:link-type: doc
:img-background: ../../_static/matplotlib-logo-dark.svg
:class-img-bottom: dark-light

.. grid-item-card::
:link: bokeh
:link-type: doc
:img-background: ../../_static/bokeh-logo-dark.svg
:class-img-bottom: dark-light

.. grid:: 2
:class-container: only-light
Expand Down
14 changes: 14 additions & 0 deletions docs/source/api/managers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@ Plotting
PlotCollection.plot_iterator
PlotCollection.show

Attributes
..........

.. autosummary::
:toctree: generated/

PlotCollection.aes
PlotCollection.viz
PlotCollection.aes_set
PlotCollection.base_loop_dims
PlotCollection.data

Facetting and aesthetics mapping
................................

.. autosummary::
:toctree: generated/

PlotCollection.generate_aes_dt
PlotCollection.get_aes_as_dataset
PlotCollection.get_aes_kwargs
PlotCollection.update_aes
PlotCollection.update_aes_from_dataset

Other
.....
Expand Down
21 changes: 14 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# -- Project information

_metadata = metadata("arviz-base")
_metadata = metadata("arviz-plots")

project = _metadata["Name"]
author = _metadata["Author-email"].split("<", 1)[0].strip()
Expand Down Expand Up @@ -74,8 +74,8 @@
plot_html_show_source_link = False

extlinks = {
"issue": ("https://github.com/arviz-devs/arviz-base/issues/%s", "GH#%s"),
"pull": ("https://github.com/arviz-devs/arviz-base/pull/%s", "PR#%s"),
"issue": ("https://github.com/arviz-devs/arviz-plots/issues/%s", "GH#%s"),
"pull": ("https://github.com/arviz-devs/arviz-plots/pull/%s", "PR#%s"),
}

copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
Expand Down Expand Up @@ -106,14 +106,21 @@

intersphinx_mapping = {
"arviz_org": ("https://www.arviz.org/en/latest/", None),
"dask": ("https://docs.dask.org/en/latest/", None),
"datatree": ("https://xarray-datatree.readthedocs.io/en/latest/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"python": ("https://docs.python.org/3/", None),
"xarray": ("https://docs.xarray.dev/en/stable/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"bokeh": ("https://docs.bokeh.org/en/2.4.3", None),
}

# -- Options for HTML output

html_theme = "furo"
# html_static_path = ["_static"]
html_theme = "sphinx_book_theme"
html_context = {"default_mode": "light"}
html_theme_options = {
"logo": {
"image_light": "_static/ArviZ.png",
"image_dark": "_static/ArviZ_white.png",
}
}
html_static_path = ["_static"]
1 change: 1 addition & 0 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Plotting backends have to be added manually.

tutorials/plots_intro
tutorials/intro_to_plotcollection
tutorials/compose_own_plot
```

```{toctree}
Expand Down
45 changes: 45 additions & 0 deletions docs/source/tutorials/compose_own_plot.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "06954271-7cc3-4651-9d1b-27352bbd0372",
"metadata": {},
"source": [
"(compose_own_plot)=\n",
"# Create your own chart with `PlotCollection`\n",
"\n",
":::{warning} work in progress\n",
":::"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d163d20-7725-4b21-8f41-448f8ba06691",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "ArviZ (minimal env)",
"language": "python",
"name": "arviz"
},
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
9,177 changes: 8,922 additions & 255 deletions docs/source/tutorials/intro_to_plotcollection.ipynb

Large diffs are not rendered by default.

136 changes: 94 additions & 42 deletions docs/source/tutorials/plots_intro.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test = [
"h5netcdf",
]
doc = [
"furo",
"sphinx-book-theme",
"myst-parser[linkify]",
"myst-nb",
"sphinx-copybutton",
Expand Down
54 changes: 53 additions & 1 deletion src/arviz_plots/backend/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,58 @@ def get_default_aes(aes_key, n, kwargs):
return get_agnostic_default_aes(aes_key, n, kwargs)


def scale_fig_size(figsize, rows=1, cols=1, figsize_units="inches"):
"""Scale figure properties according to figsize, rows and cols.

Parameters
----------
figsize : (float, float) or None
Size of figure in `figsize_units`
rows : int
Number of rows
cols : int
Number of columns
figsize_units : {"inches", "dots"}
Ignored if `figsize` is ``None``

Returns
-------
figsize : (float, float) or None
Size of figure in dots
labelsize : float
fontsize for labels
linewidth : float
linewidth
"""
if figsize is None:
width = 800
height = (100 * rows + 100) ** 1.1
figsize_units = "dots"
else:
width, height = figsize
cols *= 100
rows *= 100
if figsize_units == "inches":
warnings.warn(
f"Assuming dpi=100. Use figsize_units='dots' and figsize={figsize} "
"to stop seeing this warning"
)
width *= 100
height *= 100
elif figsize_units != "dots":
raise ValueError(f"figsize_units must be 'dots' or 'inches', but got {figsize_units}")

val = (width * height) ** 0.5
val2 = (cols * rows) ** 0.5
scale_factor = val / (4 * val2)
# I didn't find any Bokeh equivalent to theme/rcParams,
# so they are hardcoded for now
labelsize = 14 * scale_factor
linewidth = 1 * scale_factor

return (width, height), labelsize, linewidth


# object creation and i/o
def show(chart):
"""Show the provided bokeh layout."""
Expand Down Expand Up @@ -104,7 +156,7 @@ def create_plotting_grid(
if figsize_units == "inches":
figsize = (figsize[0] * 100, figsize[1] * 100)
warnings.warn(
f"Assuming dpi=100. Use figsize_units='' and figsize={figsize} "
f"Assuming dpi=100. Use figsize_units='dots' and figsize={figsize} "
"to stop seeing this warning"
)
elif figsize_units != "dots":
Expand Down
48 changes: 48 additions & 0 deletions src/arviz_plots/backend/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,53 @@ def get_default_aes(aes_key, n, kwargs):
return get_agnostic_default_aes(aes_key, n, kwargs)


def scale_fig_size(figsize, rows=1, cols=1, figsize_units="inches"):
"""Scale figure properties according to figsize, rows and cols.

Parameters
----------
figsize : (float, float) or None
Size of figure in `figsize_units`
rows : int
Number of rows
cols : int
Number of columns
figsize_units : {"inches", "dots"}
Ignored if `figsize` is ``None``

Returns
-------
figsize : (float, float) or None
Size of figure in dots
labelsize : float
fontsize for labels
linewidth : float
linewidth
"""
if figsize is None:
width = rcParams["figure.figsize"][0]
height = (rows + 1) ** 1.1
figsize_units = "inches"
else:
width, height = figsize
dpi = rcParams["figure.dpi"]
cols *= dpi
rows *= dpi
if figsize_units == "inches":
width *= dpi
height *= dpi
elif figsize_units != "dots":
raise ValueError(f"figsize_units must be 'dots' or 'inches', but got {figsize_units}")

val = (width * height) ** 0.5
val2 = (cols * rows) ** 0.5
scale_factor = val / (4 * val2)
labelsize = rcParams["font.size"] * scale_factor
linewidth = rcParams["lines.linewidth"] * scale_factor

return (width, height), labelsize, linewidth


# object creation and i/o
def show(chart): # pylint: disable=unused-argument
"""Show all existing matplotlib figures."""
Expand Down Expand Up @@ -122,6 +169,7 @@ def create_plotting_grid(
sharey=sharey,
squeeze=squeeze,
width_ratios=width_ratios,
figsize=figsize,
subplot_kw=subplot_kws,
**kwargs,
)
Expand Down
Loading
Loading