Skip to content
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

legend not working for bar plot with Plotly backend #1035

Open
MarcSkovMadsen opened this issue Mar 11, 2023 · 0 comments
Open

legend not working for bar plot with Plotly backend #1035

MarcSkovMadsen opened this issue Mar 11, 2023 · 0 comments
Labels
TRIAGE type: bug Something isn't working type: upstream Anything that requires work outside hvPlot

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Mar 11, 2023

I would expect the legend attribute to also work for the Plotly backend in the example below. But it does not.

image

import hvplot.pandas  # noqa

from bokeh.sampledata.autompg import autompg_clean as df

table = df.groupby('yr').mean(numeric_only=True)
table.head()

table = df.groupby(['yr', 'origin']).mean(numeric_only=True)
table.head()

hvplot.extension("bokeh")
table.hvplot.bar(stacked=True, height=500, legend='bottom')

hvplot.extension("plotly")
table.hvplot.bar(stacked=True, height=500, legend='bottom')

HoloViews

I've tried to replicate this using HoloViews. But it seems the corresponding legend_position is only supported for the matplotlib and bokeh backends. There is an existing FR in HoloViews to support legend_position for the Plotly backend. See holoviz/holoviews#5221

It is possible to position the Plotly legend using a hook though.

import holoviews as hv  # noqa

hv.extension("plotly")

from bokeh.sampledata.autompg import autompg_clean as df

table = df.groupby(['yr', 'origin']).mean(numeric_only=True)

def hook(plot, element):
    # https://plotly.com/python/legend/#legend-positioning
    fig = plot.state
    fig["layout"]["legend"]=dict(
        yanchor="top",
        y=0.99,
        xanchor="left",
        x=0.01
    )

plot = hv.Bars(table, kdims=["yr", "origin"], vdims="mpg").opts(stacked=True, height=500, width=1000, hooks=[hook])

import panel as pn

pn.extension()

pn.panel(plot).servable()

image

Additional Context

I've been working on improving the bar docs. As a part of this I try changing the plotting backend. I would really, really like the documentation to work for all plotting backends. That is what I would expect as a user.

@MarcSkovMadsen MarcSkovMadsen added the type: bug Something isn't working label Mar 11, 2023
@MarcSkovMadsen MarcSkovMadsen added this to the 0.8.3 milestone Mar 11, 2023
@MarcSkovMadsen MarcSkovMadsen removed this from the 0.8.3 milestone Mar 12, 2023
@MarcSkovMadsen MarcSkovMadsen added TRIAGE type: upstream Anything that requires work outside hvPlot labels Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TRIAGE type: bug Something isn't working type: upstream Anything that requires work outside hvPlot
Projects
None yet
Development

No branches or pull requests

1 participant