customdata parsed incorrectly when array contains more than 1 column in piechart
未关闭
还没有人认领这个 Issue。
bug
P2
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
When using more than one column to define customdata, the data seems to be parsed as a tuple.
The example below shows three versions of the same figure:
- LEFT. Only one column of
customdata. Works as expected. - CENTER. Two columns of
customdata. The first column incustomdatais not parsed correctly when using a:.1sformat. The second column incustomdatais not parsed correctly byhovertemplateingo.Piebut is parsed correctly bytexttemplate. - RIGHT. Workaround using
customdataas a tuple and selecting its first%{customdata[0][0]}and second%{customdata[0][1]}values accordingly.
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
df = pd.DataFrame({
'country': ['A', 'B', 'C'],
'count': [10, 20, 30],
'total': [1.5e5, 4.5e4, 3.2e3],
'ratio': [0.05, 0.10, 0.15]
})
fig = make_subplots(rows=1, cols=3, specs=[[{"type": "domain"}, {"type": "domain"}, {"type": "domain"}]])
# customdata parsed correctly with only one column
fig.add_trace(go.Pie(
labels=df['country'],
values=df['count'],
customdata=df[['total']], # 1 column
hovertemplate=(
'Country: %{label}<br>'
'Count: %{value}<br>'
'Total documents: %{customdata[0]:.1s}'),
hole=0.3
),
row=1, col=1)
# Problem with customdata
fig.add_trace(go.Pie(
labels=df['country'],
values=df['count'],
customdata=df[['total', 'ratio']], # >1 columns
hovertemplate=(
'Country: %{label}<br>'
'Count: %{value}<br>'
'Total documents: %{customdata[0]:.1s}<br>'
'Ratio: %{customdata[1]:.2f}'),
texttemplate = "%{customdata[1]:.2p}", # correctly parsed
hole=0.3
),
row=1, col=2)
# Workaround
fig.add_trace(go.Pie(
labels=df['country'],
values=df['count'],
customdata=df[['total', 'ratio']], # >1 columns
hovertemplate=(
'Country: %{label}<br>'
'Count: %{value}<br>'
'Total documents: %{customdata[0][0]:.1s}<br>' # as tuple
'Ratio: %{customdata[0][1]:.2f}'),
texttemplate = "%{customdata[1]:.2p}", # correctly parsed
hole=0.3
),
row=1, col=3)
fig.show()
Tested using:
Plotly.py: 6.0.1
Pandas: 2.1.4
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先运行提供的 Plotly.py 和 Pandas 复现代码,然后跟踪多列 customdata 如何传递给 pie-chart 的 hovertemplate 格式化。完成标准是:两个 customdata 列都能以请求的格式进行渲染,且不使用 tuple-style indexing,同时单列情况和 texttemplate 的行为保持正确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- pandas, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100