我有一个堆叠的水平条形图,希望为每个图跟定义文本,放置在相应条形的中心位置。我找不到一个设置此项的属性而不使用注释的方法,但我想为每个图使用 "text",并只能对齐它。
我正在使用 Plotly 3.4.1 和 Jupyter(Plotly 离线版)。除了尝试使用注释来实现这一目标,我找不到任何关于如何做到这一点的文档,如果我想要指定明确的坐标,则注释似乎是更合适的解决方案。我想要更简单的方法(比如 "align": "center"),但是在 go.Bar 下没有找到任何属性可以用于此项。
我只想让 "80"、"20" 出现在中心位置,而不是靠右对齐。
我正在使用 Plotly 3.4.1 和 Jupyter(Plotly 离线版)。除了尝试使用注释来实现这一目标,我找不到任何关于如何做到这一点的文档,如果我想要指定明确的坐标,则注释似乎是更合适的解决方案。我想要更简单的方法(比如 "align": "center"),但是在 go.Bar 下没有找到任何属性可以用于此项。
我只想让 "80"、"20" 出现在中心位置,而不是靠右对齐。
from plotly.offline import iplot, plot, init_notebook_mode
import plotly.graph_objs as go
def getStackedSentimentHbar():
trace0 = go.Bar(
y=["A","B"],
x=[20,80],
orientation = 'h',
text=["20","80"],
textposition="inside",
hoverinfo = "none",
)
trace1 = go.Bar(
y=["A","B"],
x=[80,20],
orientation = 'h',
text=["80","20"],
textposition="inside",
hoverinfo = "none",
)
data = [trace0,trace1]
layout = go.Layout(
barmode='stack',
showlegend=False,
xaxis=dict(
showgrid=False,
zeroline=False,
showline=False,
ticks='',
showticklabels=False
),
yaxis=dict(
showgrid=False,
zeroline=False,
showline=False,
ticks='',
showticklabels=True
),
margin = dict(
l = 200,
r = 50,
b = 50,
t = 50,
pad = 10
),
font=dict(
family='Heebo',
size=18,
color='#000000'
)
)
fig = go.Figure(data=data, layout=layout)
return fig
init_notebook_mode()
fig = getStackedSentimentHbar()
iplot(fig)