plotly / plotly/plotly.py

legend.maxheight not honored in Jupyter / notebook renderer though works in browser

Offen
#5,378 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P2
Vorherrschende Sprache
Python
Sterne
18.8k
Forks
2.8k
Ø Merge
16 Std. 26 Min.
Gemergte PRs (30 T.)
21

Beschreibung

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.005 setting (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.


Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das bereitgestellte Plotly Express-Beispiel mit fig.show() in einem Jupyter-Notebook und mit fig.show(renderer="browser") auszuführen, und vergleiche das Verhalten der Legende mit write_html. Verfolge den auf Notebooks basierenden Renderer-Einstiegspunkt und ermittle, warum legend.maxheight nicht angewendet wird; abgeschlossen ist die Aufgabe, wenn die Notebook-Renderer die Legende konsistent mit dem Browser-Renderer begrenzen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter-notebook, python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.