plotly / plotly/plotly.py

Plotting data only on secondary_y axes ignores subplot grid

未关闭
#4,302 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

Hello,

running the following code will produce a 2x2 subplot grid with data on the primary_y axes and data on one secondary_y axes.

from plotly.subplots import make_subplots
import plotly.graph_objects as go
import numpy as np

rows = 2
cols = 2

fig = make_subplots(rows=rows, cols=cols, specs=[[{"secondary_y": True}] * cols] * rows)

fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name='1:1 primary_y',),
              secondary_y=False, row=1, col=1)

fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name=f'1:2 primary_y',),
              secondary_y=False, row=1, col=2)

fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name=f'2:1 primary_y',),
              secondary_y=False, row=2, col=1)

fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name=f'2:2 primary_y',),
              secondary_y=False, row=2, col=2)

# plot on secondary_y
fig.add_trace(go.Scatter(x=np.arange(5) + 1, y=np.arange(5), name=f'2:2 secondary_y',),
              secondary_y=True, row=2, col=2)

fig.update_layout(height=400, width=600)

fig.write_html('test_bug.html')

grafik

however if you don’t plot any data on a primary_y axes but leave the data on the secondary_y axes the height of the axes will take up the whole height of the figure

from plotly.subplots import make_subplots
import plotly.graph_objects as go
import numpy as np

rows = 2
cols = 2

fig = make_subplots(rows=rows, cols=cols, specs=[[{"secondary_y": True}] * cols] * rows)

fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name='1:1 primary_y',),
              secondary_y=False, row=1, col=1)

fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name=f'1:2 primary_y',),
              secondary_y=False, row=1, col=2)

fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name=f'2:1 primary_y',),
              secondary_y=False, row=2, col=1)

# fig.add_trace(go.Scatter(x=np.arange(5), y=np.arange(5), name=f'2:2 primary_y',),
#               secondary_y=False, row=2, col=2)

# plot on secondary_y
fig.add_trace(go.Scatter(x=np.arange(5) + 1, y=np.arange(5), name=f'2:2 secondary_y',),
              secondary_y=True, row=2, col=2)

fig.update_layout(height=400, width=600)

fig.write_html('test_bug.html')

grafik

is this behaviour intentional?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 make_subplots、add_trace 和 secondary_y 选项重现这两个示例,并比较生成的 test_bug.html 文件。调查当省略第 2 行第 2 列中的主 trace 时,子图网格如何分配坐标轴域。完成标准是:仅使用次坐标轴的数据仍限制在其 2x2 子图单元格内,而不是扩展到整个图表。

由索引模型根据 Issue 内容生成。

评估

技术栈
numpy, python
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。