Skip to content

Conversation

@Azaya89
Copy link
Collaborator

@Azaya89 Azaya89 commented Apr 17, 2025

closes #1536

This PR adds API reference examples to the following plot methods:

@Azaya89 Azaya89 added the NF SDG 2025 NumFocus Software Development Grant 2025 label Apr 17, 2025
@Azaya89
Copy link
Collaborator Author

Azaya89 commented Apr 17, 2025

The signature defs in the scatter plot method still needs to be updated I think, as well as adding some more examples to it.

"\n",
"df = hvsampledata.penguins(\"pandas\")\n",
"\n",
"stacked_df = df.groupby(\"species\")[[\"bill_length_mm\", \"bill_depth_mm\"]].mean().reset_index()\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 don't think calling reset_index() is required?

"cell_type": "markdown",
"metadata": {},
"source": [
"### Simple vertical bar plot"
Copy link
Member

Choose a reason for hiding this comment

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

If possible, it'd be nice if the first example could be independent of hvsampledata (e.g. with dummy data generated with pandas/numpy), so users who don't have it installed have one chance to run this one easily.

Copy link
Member

Choose a reason for hiding this comment

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

I think you can borrow a bit more from https://hvplot.holoviz.org/reference/tabular/bar.html:

  • multi-index
  • wide vs long data

I also like the short sentences that precede the plots.

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to show at least in one cell the .head() of the penguins dataset. Also I think I'd be in favor of showing at least in one cell the content of stacked_df. Pandas users wouldn't struggle too much understanding the shape of this dataframe but it's still cognitive load we can avoid.

"df = hvsampledata.earthquakes(\"pandas\")\n",
"\n",
"TBD"
"df.hvplot.scatter(\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 seems to me this is a bit of a too "complicated" example (tiles) for the first one on this page.

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. Will change it.

A color or a Field name to draw the color of the marker from
s : int, optional, also available as 'size'
The size of the marker
by : string, optional
Copy link
Member

Choose a reason for hiding this comment

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

I think these options were added by Marc when he improved all the docstrings. I understand why he did that, to make them available in VS Code when you use hvPlot as follows:

from hvplot import hvPlot

hvPlot(df).scatter(...

It duplicates docstrings which isn't good. Removing them affects the UX in an IDE, which isn't good either. I'll open an issue to track this, I think we could define a subset of important options all methods should have (or have a way to declare which generic options a given method should be augmented with in its docstring), and have a pre-commit step that makes sure we don't have to manually duplicate docstrings.

@Azaya89
Copy link
Collaborator Author

Azaya89 commented May 6, 2025

I just pushed 8878346 to reset this PR so i can figure out the directory tree much more easily. Still a WIP.

@Azaya89 Azaya89 removed the NF SDG 2025 NumFocus Software Development Grant 2025 label May 9, 2025
@Azaya89 Azaya89 added the NF SDG 2025 NumFocus Software Development Grant 2025 label May 16, 2025
" y=\"Apple\",\n",
" y2=\"Microsoft\",\n",
" alpha=0.4,\n",
" line_color=\"#e87508\",\n",
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 should be possible to set a different line_color for each individual line in the plot (y and y2) but right now it's not.

"## Examples\n",
"\n",
"TBD"
"### `Filled Contours for Temperature Regions`\n",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why is there even a contourf element instead of just adding the filled paramater to the contour element?

Copy link
Member

Choose a reason for hiding this comment

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

"id": "b27350ca",
"metadata": {},
"source": [
"# hvPlot.dataset\n",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How many people actually use this element in real life? Is it necessary to continue maintaining it?

Copy link
Member

Choose a reason for hiding this comment

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

Probably very few. Might be good to ask Philipp for feedback.

@Azaya89 Azaya89 requested a review from maximlt June 13, 2025 16:47
@maximlt maximlt marked this pull request as ready for review July 30, 2025 14:49
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 while ago already I added some inline review comments. I've reviewed the documented notebooks, modified them a bit, and added the missing ones. This is good to go, thanks @Azaya89 !!!

'sphinxext.rediraffe',
'numpydoc',
'sphinxcontrib.mermaid',
'sphinx.ext.intersphinx',
Copy link
Member

Choose a reason for hiding this comment

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

Already added in nbsite.

"cell_type": "markdown",
"metadata": {},
"source": [
"### `Stacked Area for Multiple Series`\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've removed the quotes in the headings.

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

Choose a reason for hiding this comment

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

Changed this example in favor of apple_stocks and display low/high prices area (I thought it was a more realistic use case).

Copy link
Member

Choose a reason for hiding this comment

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

Reworked it a bit to use a dataset that makes a bit more sense when using stacked=True.

"cell_type": "markdown",
"metadata": {},
"source": [
"### `Combining contourf with Transparency`\n",
Copy link
Member

Choose a reason for hiding this comment

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

In general, in these pages the focus should be on documenting the plot-specific options, like levels in this case, which has no example on this page.

"import numpy as np\n",
"\n",
"df = pd.DataFrame({'values': np.random.normal(loc=0, scale=1, size=1000)})\n",
"df.hvplot.hist(y='values', bin_range=(-1, 1), title='Histogram in Range -1 to 1') # Didn't work?"
Copy link
Member

Choose a reason for hiding this comment

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

"source": [
"### Basic Histogram with bins\n",
"\n",
"You can control the number of bins or specify bin edges."
Copy link
Member

Choose a reason for hiding this comment

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

In a reference document, we can add more examples that go beyond the simplest one.

".. backend-styling-options:: ohlc\n",
"```\n",
"\n",
"## Examples\n",
Copy link
Member

Choose a reason for hiding this comment

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

The gallery page (https://hvplot.holoviz.org/reference/tabular/ohlc.html) contains an example describing how neg_color, pos_color, line_color and bar_width can be used to control the plot display. These are keywords specific to this plot. I've documented them.

"## Examples\n",
"\n",
"TBD"
"### `Lissajous Curve`\n",
Copy link
Member

Choose a reason for hiding this comment

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

Nice to have a non-geographic example but still I think that's likely to be the most common use case and why it was included in the reference gallery (https://hvplot.holoviz.org/reference/tabular/paths.html).

@maximlt maximlt merged commit 4deb1ae into main Jul 30, 2025
11 checks passed
@maximlt maximlt deleted the plot-methods branch July 30, 2025 15:00
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.

Improve the documentation of the plot methods

3 participants