legend.maxheight not honored in Jupyter / notebook renderer though works in browser
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 18.8k
- Fork
- 2.8k
- Merge medio
- 16h 26m
- PR unite (30g)
- 21
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo l'esempio Plotly Express fornito con fig.show() in un notebook Jupyter e con fig.show(renderer="browser"), confrontando il comportamento della legenda con write_html. Segui il punto di ingresso del renderer basato sui notebook e determina perché legend.maxheight non viene applicato; il lavoro è completato quando i renderer dei notebook limitano la legenda in modo coerente con il renderer del browser.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- jupyter-notebook, python
- Ambito
- data-visualization
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100