holoviz / holoviz/hvplot

Legend not showing for bar + line plot

Open
#916 4 comments 5 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

hvplot==0.8.1,holoviews=1.14.9

I want to show a `bar * line` plot with a legend. I've tried all kinds of combinations of `legend="bottom"` and `show_legend=True`. But I cannot get the legend to show. https://discourse.holoviz.org/t/how-do-i-show-legend-for-single-bar-and-single-bar-line-plot/4267.

Here is an example. I can see hvplot recognizes the `legend` argument and `.opts` the `show_legend` argument. But it does not show the legend.

```python
import pandas as pd
import hvplot.pandas

df = pd.DataFrame(
{
"actual": [100, 150, 125, 140, 145, 135, 123],
"forecast": [90, 160, 125, 150, 141, 141, 120],
"numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5],
"date": pd.date_range("2022-01-03", "2022-01-09"),
"string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
},
)
bar = df.hvplot.bar(x="string", y="actual", rot=90, color="#f16a6f", legend="bottom", xlabel="day", ylabel="value")
bar

forecast_line = df.hvplot.line(x="string", y="forecast", color="#1e85f7", line_width=5, legend="bottom")
forecast_markers = df.hvplot.scatter(x="string", y="forecast", color="#1e85f7", size=100, legend="bottom")
(bar * forecast_line * forecast_markers).opts(show_legend=True)
```

![image](https://user-images.githubusercontent.com/42288570/191894742-1f566ee7-5218-4e33-8a13-d37e9f608440.png)

For me this is an important example that I see often used in a business context and I want to add the example to the docstrings of `bar` or the reference example.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.