Skip to content

Document the size and layout options #1545

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

Merged
merged 13 commits into from
May 21, 2025
Merged

Document the size and layout options #1545

merged 13 commits into from
May 21, 2025

Conversation

Azaya89
Copy link
Collaborator

@Azaya89 Azaya89 commented Apr 14, 2025

fixes #1544

This PR adds the Size and Layout options to the reference docs.

@Azaya89 Azaya89 self-assigned this Apr 14, 2025
@Azaya89 Azaya89 added the NF SDG 2025 NumFocus Software Development Grant 2025 label Apr 14, 2025
@Azaya89 Azaya89 requested a review from Copilot April 14, 2025 11:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

doc/ref/plot_options/size.ipynb:12

  • [nitpick] Consider standardizing the capitalization for consistency; the notebook header uses 'Size and Layout Options' while this directive uses 'Size And Layout Options'.
.. plotting-options-table:: Size And Layout Options

Copy link
Member

@maximlt maximlt left a comment

Choose a reason for hiding this comment

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

A few quick questions on the options:

  • Should fontsize and fontscale be in the same option group?
  • Should aspect and data_aspect be in this size and layout group?

"source": [
"## `frame_width / frame_height`\n",
"\n",
"The `frame_width` and `frame_height` options determine the width and height of the data area within the plot. They define the size of the plot’s core region (excluding axes, legends, and margins), allowing precise control over how the data is displayed."
Copy link
Member

Choose a reason for hiding this comment

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

Oh cool, I had never really thought about this (or forgot!). Like in HoloViews docs, it could be nice to show two plots with frame_height/width set, one without a legend or colorbar and one with, to see the inner plots have the same dimension.

"import hvplot.xarray # noqa\n",
"import hvsampledata\n",
"\n",
"df = hvsampledata.air_temperature(\"xarray\")\n",
Copy link
Member

Choose a reason for hiding this comment

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

Pick just one timestamp to avoid the non-interactive widgets.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

"import hvplot.xarray # noqa\n",
"import hvsampledata\n",
"\n",
"df = hvsampledata.air_temperature(\"xarray\")\n",
Copy link
Member

Choose a reason for hiding this comment

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

Pick just one timestamp to avoid the non-interactive widgets.

"import hvplot.xarray # noqa\n",
"import hvsampledata\n",
"\n",
"df = hvsampledata.air_temperature(\"xarray\")\n",
Copy link
Member

Choose a reason for hiding this comment

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

Pick just one timestamp to avoid the non-interactive widgets.

"source": [
"## `padding`\n",
"\n",
"The `padding` option expands the plot’s automatically computed axis limits by a given fraction. When hvPlot determines the x and y ranges based on your data, it finds the minimum and maximum values needed to display all points. With padding applied, these ranges are extended by the specified fraction so that data points near the edges have more space. The padding value can be given as a single number for uniform padding, a tuple to specify different padding for the x- and y-axes, or even a nested tuple to set distinct padding for the upper and lower bounds of each axis."
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's a good idea to set tiles=True in this example (the axes are distributed differently). Might be best to use a simpler dummy and more geometric dataset in this case.

Something like this maybe:

import pandas as pd

df = pd.DataFrame({'x': [0, 1, 0, -1], 'y': [-1, 0, 1, 0]})
df.hvplot.scatter(x='x', y='y', padding=(0.5, 0.1))

image

Copy link
Member

Choose a reason for hiding this comment

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

Should the file be named size_and_layout?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems unnecessarily long IMO.

Copy link
Member

Choose a reason for hiding this comment

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

How about size_layout? More descriptive URL helps with SEO I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

@Azaya89
Copy link
Collaborator Author

Azaya89 commented Apr 30, 2025

  • Should fontsize and fontscale be in the same option group?

Yeah, I think so. I'll move fontscale to Styling Options then.

  • Should aspect and data_aspect be in this size and layout group?

Hmm, I think so.

@Azaya89 Azaya89 requested a review from Copilot April 30, 2025 18:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR documents the new Size and Layout options for plots and updates internal option categorizations accordingly.

  • Introduces the new options “aspect” and “data_aspect” with detailed documentation.
  • Reassigns the “fontscale” option from the Size and Layout section to the Axis Options.
  • Updates the documentation index and adds a new notebook detailing these changes.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
hvplot/converter.py Updates docstrings and internal option lists to reclassify axis and size/layout options.
doc/ref/plotting_options/size_layout.ipynb Adds a comprehensive notebook demonstrating the new size and layout options.
doc/ref/plotting_options/index.md Links the new size/layout documentation for easier navigation.
Comments suppressed due to low confidence (1)

hvplot/converter.py:378

  • Since 'fontscale' has been reclassified to the Axis Options, ensure the accompanying documentation consistently reflects its new categorization and rationale for the change.
    fontscale : number

@@ -511,7 +511,8 @@ class HoloViewsConverter:
]

This comment was marked as resolved.

Copy link
Member

@maximlt maximlt left a comment

Choose a reason for hiding this comment

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

I've pushed a few minor changes and left some comments that are mostly about aspect.

"\n",
"The `aspect` option controls the overall shape of the plot by setting the ratio of its width to its height.\n",
"You can specify 'auto', 'equal', or a numeric value:\n",
"- 'auto': The plot determines its own aspect ratio (default).\n",
Copy link
Member

Choose a reason for hiding this comment

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

I tried setting aspect='auto' and got an error. It's important that we try the options we document to make sure they work and do what we expect.

File [~/dev/hvplot/.pixi/envs/docs/lib/python3.11/site-packages/holoviews/plotting/plot.py:1376](http://localhost:8889/lab/workspaces/auto-h/tree/~/dev/hvplot/.pixi/envs/docs/lib/python3.11/site-packages/holoviews/plotting/plot.py#line=1375), in GenericElementPlot.get_padding(self, obj, extents)
   1374 yspan = y1-y0 if util.is_number(y0) and util.is_number(y1) else None
   1375 aspect = self.get_aspect(xspan, yspan)
-> 1376 if aspect > 1:
   1377     xpad = tuple(xp[/](http://localhost:8889/aspect)[aspect](http://localhost:8889/aspect) for xp in xpad) if isinstance(xpad, tuple) else xpad[/](http://localhost:8889/aspect)[aspect](http://localhost:8889/aspect)
   1378 else:

TypeError: '>' not supported between instances of 'str' and 'int'

"The `aspect` option controls the overall shape of the plot by setting the ratio of its width to its height.\n",
"You can specify 'auto', 'equal', or a numeric value:\n",
"- 'auto': The plot determines its own aspect ratio (default).\n",
"- 'equal': Ensures the axes have the same scaling (e.g. for square plots).\n",
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean with for square plots?

Copy link
Member

Choose a reason for hiding this comment

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

In fact, I tried passing down aspect='square' and that worked too.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe in a case like that where the argument accepts a few values, it's good to show them all. Let me know what you think.

(
      df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', frame_width=200)
    + df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', frame_width=200, aspect=0.6)
    + df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', frame_width=200, aspect='square')
    + df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', frame_width=200, aspect='equal')
).cols(2)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a better example. I've used it in the notebook instead of the former one.

"id": "c99dceda-b76f-450a-90ac-06735a1b001c",
"metadata": {},
"source": [
"## `frame_width / frame_height`\n",
Copy link
Member

Choose a reason for hiding this comment

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

Interestingly HoloViews seems to align well plots in a layout by default, without having to set frame_width explicitly:
image

Copy link
Member

Choose a reason for hiding this comment

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

I've updated the notebook with a different approach.

image

"id": "de030cee-46a2-4d8d-b12a-e685bd616e27",
"metadata": {},
"source": [
"## `data_aspect`\n",
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nice to write which option takes precedence between aspect and data_aspect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AFAICT, aspect and data_aspect do different things. aspect controls the shape of the plot i.e, ratio of frame_width to frame_height while data_aspect controls the scaling of the data units i.e, ratio of the unit on the x-axis to the unit on the y-axis.

I've modified the documentation to be more explanatory.

@Azaya89 Azaya89 requested a review from maximlt May 19, 2025 11:49
"(option-aspect)=\n",
"## `aspect`\n",
"\n",
"The `aspect` option controls the **frame** shape by setting the ratio of its width to its height. By default (`aspect=None`), HoloViews chooses an appropriate ratio automatically. Use:\n",
Copy link
Member

Choose a reason for hiding this comment

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

To understand, what do you mean with HoloViews choosing an appropriate ratio automatically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It means the ratio used is either the default or the specified frame width/height. I think I'll have to rewrite that as it is a bit vague.

@maximlt maximlt merged commit 7ef626b into holoviz:main May 21, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NF SDG 2025 NumFocus Software Development Grant 2025
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document the size and layout options
2 participants