Plotly 条形图上的错误栏阻止的文本
Text blocked by error bars on Plotly bar graph
我正在尝试绘制带有误差线和数据标签的条形图,但我找不到如何更改文本的位置以使误差线不干扰标签。 This is an example of what I currently have,这里是代码:
x = [1, 2, 3, 4, 5, 6]
y = [100, 90, 80, 70, 60, 50]
y_err = [5, 6, 7, 8, 9, 10]
fig = go.Figure(data=go.Bar(x=x, y=y, error_y_array=y_err, text=y, textposition="inside"))
fig.show()
我希望标签最好位于栏的底部,但确保数据不被覆盖的任何其他方法也适用。我需要数据在条内并水平放置。谢谢!
我只是简单地注释每个条,textposition
的唯一有效参数是`['inside'、'outside' 和'auto']。所以在那种情况下循环遍历列表并添加如下文本:
import plotly.graph_objects as go
x = [1, 2, 3, 4, 5, 6]
y = [100, 90, 80, 70, 60, 50]
y_err = [5, 6, 7, 8, 9, 10]
fig = go.Figure(data=go.Bar(x=x, y=y, error_y_array=y_err))
i=0
text_height = 5
for x_val in x:
fig.add_annotation(
x=x_val,
y=text_height,
text=str(y[i]),
showarrow=False,
font=(dict(color='white'))
)
i = i+1
输出:
我正在尝试绘制带有误差线和数据标签的条形图,但我找不到如何更改文本的位置以使误差线不干扰标签。 This is an example of what I currently have,这里是代码:
x = [1, 2, 3, 4, 5, 6]
y = [100, 90, 80, 70, 60, 50]
y_err = [5, 6, 7, 8, 9, 10]
fig = go.Figure(data=go.Bar(x=x, y=y, error_y_array=y_err, text=y, textposition="inside"))
fig.show()
我希望标签最好位于栏的底部,但确保数据不被覆盖的任何其他方法也适用。我需要数据在条内并水平放置。谢谢!
我只是简单地注释每个条,textposition
的唯一有效参数是`['inside'、'outside' 和'auto']。所以在那种情况下循环遍历列表并添加如下文本:
import plotly.graph_objects as go
x = [1, 2, 3, 4, 5, 6]
y = [100, 90, 80, 70, 60, 50]
y_err = [5, 6, 7, 8, 9, 10]
fig = go.Figure(data=go.Bar(x=x, y=y, error_y_array=y_err))
i=0
text_height = 5
for x_val in x:
fig.add_annotation(
x=x_val,
y=text_height,
text=str(y[i]),
showarrow=False,
font=(dict(color='white'))
)
i = i+1
输出: