hvplot
hvplot copied to clipboard
Legend not showing for bar + line plot
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.
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)
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.
I agree this looks like a common kind of plot and that this should work.
I have the same problem. Any updates?
No update yet on this, you would anyway see a link to a PR mentioned in this issue if someone was working on fixing this. Let us know if you'd like to tackle this, we'd be very happy to help you.
Thanks, @maximlt. I wish I had the skills to tackle something like this--thanks for all that you and your fellow developers do!