legend.maxheight not honored in Jupyter / notebook renderer though works in browser
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 18.8k
- Forks
- 2.8k
- Merge médio
- 16h 26min
- PRs com merge (30d)
- 21
Descrição
Description
I found that when using legend.maxheight in Plotly (>= 6.3), it works as expected when rendering via browser (e.g. fig.show(renderer="browser") or write_html). However, when using Jupyter Notebook (or similar notebook-based renderers), the maxheight setting is ignored / not reflected — the legend expands or overflows as if maxheight were not applied.
This inconsistent behavior suggests that the notebook renderer is not honoring legend.maxheight, which hampers consistent formatting of legends in notebook environments.
Code Example to Reproduce
import plotly.express as px
from plotly import data
df = data.gapminder().query("year==2007 and continent == 'Europe'")
fig = px.scatter(
df,
x="gdpPercap",
y="lifeExp",
color="country",
size="pop",
size_max=45,
title="Life Expectancy vs. GDP per Capita in 2007 (by Country)",
labels={"gdpPercap": "GDP per Capita"},
)
fig.update_layout(
xaxis=dict(side="top"),
legend=dict(
orientation="h",
yanchor="bottom",
y=-0.35,
xanchor="center",
x=0.5,
maxheight=0.005, # comment out this line to see legend take up ~0.5 of plotting area
title_text="Country"
),
)
# Display inline in notebook
fig.show()
# Display via browser
fig.show(renderer="browser")
When executed:
- In browser renderer, the legend is constrained in height per the
maxheight=0.005setting (i.e. 0.5% of plotting height). - In notebook renderer, the legend is not constrained and expands beyond that, ignoring the
maxheight.
Expected Behavior
The legend.maxheight setting should be honored consistently across all renderers, including the notebook-based inline renderers inside Jupyter or related environments. That is, legends should be constrained to the height specified by maxheight, even when showing inline.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece executando o exemplo fornecido do Plotly Express com fig.show() em um notebook Jupyter e com fig.show(renderer="browser"), comparando o comportamento da legenda com write_html. Rastreie o ponto de entrada do renderer baseado em notebook e determine por que legend.maxheight não é aplicado; considera-se concluído quando os renderers de notebook restringem a legenda de forma consistente com o renderer do navegador.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- jupyter-notebook, python
- Domínio
- data-visualization
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100