df.hvplot.area produces incorrect areas
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 124
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 1
Description
#### ALL software version info
(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)
Software Version Info
```plaintext
# Name Version Build Channel
bokeh 3.7.3 py311h06a4308_0
holoviews 1.21.0 py311h06a4308_0
hvplot 0.12.0 py311h06a4308_0
jupyter 1.1.1 py311h06a4308_0
jupyter-black 0.4.0 pyhd8ed1ab_1 conda-forge
jupyter-lsp 2.2.5 py311h06a4308_0
jupyter-server-proxy 4.5.0 pypi_0 pypi
jupyter_bokeh 4.0.5 py311h5eee18b_0
jupyter_client 8.6.3 py311h06a4308_0
jupyter_console 6.6.3 py311h06a4308_0
jupyter_core 5.8.1 py311h06a4308_0
jupyter_events 0.12.0 py311h06a4308_0
jupyter_server 2.16.0 py311h06a4308_0
jupyter_server_terminals 0.5.3 py311h06a4308_0
jupyterlab 4.4.4 py311h06a4308_0
jupyterlab-optuna 0.2.4 pypi_0 pypi
jupyterlab_pygments 0.3.0 py311h06a4308_0
jupyterlab_server 2.27.3 py311h06a4308_0
jupyterlab_widgets 3.0.15 py311h06a4308_0
marimo 0.24.0 pypi_0 pypi
```
#### Description of expected behavior and the observed behavior
I can't really explain which areas are being shaded here, but if you try and overlay area plots `by` a category, the shaded areas are incorrect. See screenshots below.
I don't have a good grasp on the codebase so I didn't trace to find a probable cause.
#### Complete, minimal, self-contained example code that reproduces the issue
```python
import numpy as np
import polars as pl
import hvplot.polars
import holoviews as hv
hv.extension("bokeh")
x = np.linspace(0, 10, 100)
df = pl.DataFrame({
"x": np.tile(x, 2),
"lower": np.concatenate([
np.sin(x) - 0.2,
np.cos(x) - 0.2,
]),
"upper": np.concatenate([
np.sin(x) + 0.2,
np.cos(x) + 0.2,
]),
"cat": np.concatenate([
np.repeat("A", len(x)),
np.repeat("B", len(x)),
]),
})
# This behaves as expected.
line_df = (
df
.select("x", "upper", "cat")
.rename({"upper": "y"})
)
line = line_df.hvplot.line(
x="x",
y="y",
by="cat",
width=600,
height=300,
)
# This does not.
area = df.hvplot.area(
x="x",
y="lower",
y2="upper",
by="cat",
width=600,
height=300,
alpha=0.2,
)
display((line * area).opts(title="Incorrect Areas Shaded"))
display(df.filter(pl.col("cat") == "A").hvplot.area(
x="x",
y="lower",
y2="upper",
label="A",
# by="cat",
width=600,
height=300,
alpha=0.2,
) * df.filter(pl.col("cat") == "B").hvplot.area(
x="x",
y="lower",
y2="upper",
label="B",
# by="cat",
width=600,
height=300,
alpha=0.2,
) * line.opts(title="Correct Areas Shaded"))
```
#### Stack traceback and/or browser JavaScript console output
#### Screenshots or screencasts of the bug in action
- [ ] I may be interested in making a pull request to address this
Contributor guide
Research direction
Start by running the minimal Python example in the issue with the listed hvPlot, HoloViews, Bokeh, and Polars versions, comparing the grouped area plot with the separately filtered plots. Trace the area rendering path used by df.hvplot.area when by="cat" is set; done means the overlaid areas match the individually filtered A and B plots.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100