英文:
Remove Data from X Axis Labels plotly
问题
标签 = ["示例A", "示例B", "示例C", "示例D", "示例E", "示例F", "示例G", "示例H", "示例I", "示例J", "示例K", "示例L", "示例M", "示例N", "示例O", "示例P", "示例Q", "示例R", "示例S", "示例T"]
宽度 = np.array([7000, 5000, 4000, 4000, 3000, 2000, 2000, 2000, 2000, 1800, 1700, 1500, 1300, 1200, 1200, 1100, 1000, 1000, 1000, 1000])
数据 = {"5": [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
"4": [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
"3": [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
"2": [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
"1": [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]}
图表 = go.Figure()
for 键 in 数据:
图表.add_trace(go.Bar(
name=键,
y=数据[键],
x=np.cumsum(宽度) - 宽度,
width=宽度,
customdata=np.transpose([标签]),
textposition="inside",
insidetextanchor="middle",
))
图表.update_xaxes(
tickvals=np.cumsum(宽度) - 宽度 / 2,
ticktext=["%s<br>%d" % (l, w) for l, w in zip(标签, 宽度)]
)
图表.update_layout(
barmode="stack",
uniformtext=dict(mode="hide", minsize=18),
height=1000,
width=2000,
)
英文:
Is there a way to remove the x axis data from the x axis? I need the labels, just not the data/volume. (i.e display "Example A", not "Example A 7000")
labels = ["Example A","Example B","Example C","Example D","Example E","Example F","Example G","Example H","Example I","Example J","Example K","Example L","Example M","Example N","Example O","Example P","Example Q","Example R","Example S","Example T",]
widths = np.array([7000,5000,4000,4000,3000,2000,2000,2000,2000,1800,1700,1500,1300,1200,1200,1100,1000,1000,1000,1000,])
data = { "5": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"4": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"3": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"2": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"1": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],}
fig = go.Figure()
for key in data:
fig.add_trace(go.Bar(
name=key,
y=data[key],
x=np.cumsum(widths)-widths,
width=widths,
customdata=np.transpose([labels]),
textposition="inside",
insidetextanchor = "middle",
fig.update_xaxes(
tickvals=np.cumsum(widths)-widths/2,
ticktext= ["%s<br>%d" % (l, w) for l, w in zip(labels, widths)])
fig.update_layout(
barmode="stack",
uniformtext=dict(mode="hide", minsize=18),
height = 1000,
width = 2000,)
答案1
得分: 1
你明确地在这一行中将宽度包含为标签:
["%s<br>%d" % (l, w) for l, w in zip(labels, widths)]
将其更改为:
["%s" % l for l in labels]
然后它应该可以工作
英文:
You're explicitly including the widths as labels in this line:
["%s<br>%d" % (l, w) for l, w in zip(labels, widths)]
Change that to:
["%s" % l for l in labels]
And it should work
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论