我正在尝试在堆叠的水平条形图中显示数字,并且已经弄清楚了如何显示数字。但是,由于我有一些个位数和两位数,所以这些数字的方向有些奇怪。一位数字显示与两位数不同。是否有人建议我如何更改方向,以便水平堆叠的条显示水平方向的数字?
我尝试在情节上执行textposition =“ auto”。
fig = go.Figure()
fig.add_trace(go.Bar(x = publicstperc,
y = publicstate_df.index,
orientation = "h", name = "Public",
marker_color = "rgb(41,84,140)",
text = publicstate_df["Number of Public Schools"],
textposition = "auto"))
fig.add_trace(go.Bar(x = privatenpperc,
y = privatenpstate_df.index,
orientation = "h", name = "Private-Nonprofit",
marker_color = "rgb(86,149,232)",
text = privatenpstate_df["Number of Private-Nonprofit Schools"],
textposition = "auto"))
fig.add_trace(go.Bar(x = proprietaryperc,
y = proprietarystate_df.index,
orientation = "h", name = "Proprietary",
marker_color = "rgb(179,232,255)",
text = proprietarystate_df["Number of Proprietary Schools"],
textposition = "auto"))
fig.update_xaxes(range=[0,100])
fig.update_layout(title_text = "School Types Participation by State",
barmode='stack',
height = 1250,
width = 1000)
fig.show()
我希望数字可以垂直显示,因为它是水平堆叠的图表,但是我发现单位数字可以水平显示。This is what my plot looks like:
答案 0 :(得分:0)
您可以在textangle=0
调用中添加go.Bar(...)
,以在所有情况下强制文本为水平。