plotly / plotly/plotly.js

Horizontal Stacked Bar Labels Cut Off

未关闭
#6,651 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3
主要语言
JavaScript
星标
18.3k
派生
2k
平均合并
2 天 12 小时
30 天内合并 PR
28

描述

Hello! I've been encountering some behavior with labelling on stacked horizontal bar charts that I feel is somewhat strange.

Basically, when I try to add a label to each section of the stacked bar, everything works fine until I adjust the range of the x-axis to get rid of the grey space to the right of the bars. It looks like if the sum of any of the bars goes even slightly over the range of the x-axis, it causes some labels to not show up. What confuses me, and makes me unsure if this is intended or not, is that it appears as if the labels are correctly appearing in the JSON, but don't actually show up on the graph.

Here's an example:

import pandas as pd
import plotly.graph_objects as go

summary_figure = go.Figure()

summary_figure.add_trace(go.Bar(
  name="Women",
  text=["Women"]*4, 
  y = ["A","B","C","D"],
  x = [50,60,70,85],
  orientation = 'h',
  textfont_color="white",
  textangle=0,
  textposition="inside",
  insidetextanchor= "start",
  cliponaxis=False,
  ))
summary_figure.add_trace(go.Bar(
  name="Men",
  text=["Men"]*4, 
  y = ["A","B","C","D"],
  x = [50.001,40.001,30,15],
  orientation = 'h',
  textfont_color="white",
  textangle=0,
  textposition="inside",
  insidetextanchor= "start",
  cliponaxis=False,
  ))
summary_figure.update_layout(
  barmode='stack',)

summary_figure.update_xaxes(range=[0, 100])      
summary_figure.show()

image

In this example, "Men" appears in the JSON four times, but only gets displayed twice.

Because of tiny rounding discrepancies in our data, this behavior has led to a lot of confusion for my team. If it's intended, I'd love if there was some sort of warning to make it known that the bar is being truncated.

Thanks!

贡献指南

打开贡献指南

从这里开始

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

调研方向

未指定源文件、测试或入口点。首先在 plotly.js 中重现所提供的水平堆叠条形图示例,并将 x 轴范围设置为 [0, 100],然后跟踪当条形总和略微超出该范围时标签是如何渲染的。完成的要求是确定预期行为,并记录或测试由此产生的处理方式。

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

评估

技术栈
javascript
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

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