py_research.plots package#

Utilities for working with common plots.

export_html(fig, out, width=800, height=450, scale=3, name='plot', download_format='svg')[source]#

Save plotly figure to interactive html.

Parameters:
  • fig (Figure) – Plotly figure to save.

  • out (Path | str | TextIO) – Path to save to or file-like object to write to.

  • width (int) – Width of the figure in pixels.

  • height (int) – Height of the figure in pixels.

  • scale (float) – Scale factor for the figure.

  • name (str) – Name of the figure.

  • download_format (Literal['svg', 'pdf', 'png', 'jpg', 'webp']) – Format to use when downloading the figure.

plotly_to_html(fig, write_to=None, responsive=True, min_width=500, max_width=1500, max_height=600, download_format='svg', download_scale=3, full_html=True, plotly_js_url='https://cdn.jsdelivr.net/npm/plotly.js@2/dist/plotly.min.js')[source]#

Convert plotly figure to interactive (and responsive) html.

Parameters:
  • fig (Figure) – Plotly figure to save.

  • write_to (Path | str | TextIO | None) – Path to save to or file-like object to write to.

  • responsive (bool) – Whether to make the figure responsive.

  • min_width (int) – Minimum width of the figure in pixels.

  • max_width (int) – Maximum width of the figure in pixels.

  • max_height (int) – Maximum height of the figure in pixels.

  • download_format (Literal['svg', 'pdf', 'png', 'jpg', 'webp']) – Format to use when downloading the figure.

  • download_scale (float) – Scale factor for the figure resolution when downloading.

  • full_html (bool) – Whether to wrap the figure in a full html document.

  • plotly_js_url (str | None) – URL to load plotly.js library from. Defaults to the latest version on jsdelivr. Set to None to leave out the plotly.js script tag.

Returns:

HTML string.

Return type:

str

with_dropdown(group_by, dropdown_kwars=None)[source]#

Add a dropdown to a plotting function.

Parameters:
  • group_by (str) – Column to group by for the dropdown.

  • dropdown_kwars (dict[str, Any] | None) – Keyword arguments to pass to the dropdown layout.

Returns:

Decorator that adds a dropdown to the returned plot.

Return type:

Callable[[Callable[[Concatenate[DataFrame, ~P]], Figure]], Callable[[Concatenate[DataFrame, ~P]], Figure]]