plotly / plotly/plotly.py

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

Abierto
#5,378 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug P2
Lenguaje dominante
Python
Estrellas
18.8k
Forks
2.8k
Merge medio
16 h 26 min
PR fusionados (30 d)
21

Descripción

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.


Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza ejecutando el ejemplo proporcionado de Plotly Express con fig.show() en un cuaderno de Jupyter y con fig.show(renderer="browser"), y compara el comportamiento de la leyenda con write_html. Sigue el punto de entrada del renderizador basado en cuadernos y determina por qué no se aplica legend.maxheight; se considera terminado cuando los renderizadores de cuadernos limitan la leyenda de forma coherente con el renderizador del navegador.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
jupyter-notebook, python
Área
data-visualization
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.