legend.maxheight not honored in Jupyter / notebook renderer though works in browser
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,在 Jupyter notebook 中使用 fig.show() 运行提供的 Plotly Express 示例,并使用 fig.show(renderer="browser") 运行,比较图例与 write_html 的行为。跟踪基于 notebook 的 renderer 入口点,并确定为什么没有应用 legend.maxheight;当 notebook renderer 以与浏览器 renderer 一致的方式限制图例时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- jupyter-notebook, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100