如何添加标题&;python中使用plotly方法的字幕
我正在尝试使用plotly绘制条形图,我想添加标题和副标题。(在这里,您可以选择任何添加标题和副标题的示例)如何添加标题&;python中使用plotly方法的字幕,python,plotly,plotly-python,Python,Plotly,Plotly Python,我正在尝试使用plotly绘制条形图,我想添加标题和副标题。(在这里,您可以选择任何添加标题和副标题的示例) 用于绘制条形图的我的代码: import plotly.graph_objects as go fig = go.Figure() fig.add_trace(go.Bar(x=["Apple", 'Mango', 'Banana'], y=[400, 300, 500])) fig.show() 也许是这样的 import plotly.graph_obje
用于绘制条形图的我的代码:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(x=["Apple", 'Mango', 'Banana'], y=[400, 300, 500]))
fig.show()
也许是这样的
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(x=["Apple", 'Mango', 'Banana'], y=[400, 300, 500]))
fig.update_layout(
title=go.layout.Title(
text="Plot Title",
xref="paper",
x=0
),
xaxis=go.layout.XAxis(
title=go.layout.xaxis.Title(
text="x Axis",
font=dict(
family="Courier New, monospace",
size=18,
color="#7f7f7f"
)
)
),
yaxis=go.layout.YAxis(
title=go.layout.yaxis.Title(
text="y Axis",
font=dict(
family="Courier New, monospace",
size=18,
color="#7f7f7f"
)
)
)
)
fig.show()
使用
fig.update\u布局(title\u text='Your title')
作为标题。字幕没有内置选项。但是,通过将x轴标签移动到顶部,同时在右下角插入注释,可以获得所需的效果。我也尝试过其他y值,但似乎没有办法在绘图本身之外获得注释。您还可以更改标题和副标题的字体,使其从其他标签中脱颖而出
绘图:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(x=["Apple", 'Mango', 'Banana'], y=[400, 300, 500]))
fig.update_layout(title=go.layout.Title(text="Caption", font=dict(
family="Courier New, monospace",
size=22,
color="#0000FF"
)))
fig.update_layout(annotations=[
go.layout.Annotation(
showarrow=False,
text='Subtitle',
xanchor='right',
x=1,
xshift=275,
yanchor='top',
y=0.05,
font=dict(
family="Courier New, monospace",
size=22,
color="#0000FF"
)
)])
fig['layout']['xaxis'].update(side='top')
fig.show()
代码:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(x=["Apple", 'Mango', 'Banana'], y=[400, 300, 500]))
fig.update_layout(title=go.layout.Title(text="Caption", font=dict(
family="Courier New, monospace",
size=22,
color="#0000FF"
)))
fig.update_layout(annotations=[
go.layout.Annotation(
showarrow=False,
text='Subtitle',
xanchor='right',
x=1,
xshift=275,
yanchor='top',
y=0.05,
font=dict(
family="Courier New, monospace",
size=22,
color="#0000FF"
)
)])
fig['layout']['xaxis'].update(side='top')
fig.show()
我对在图表底部添加标题感兴趣。(就像我们添加图表的源代码一样)