Plotly:增加图形尺寸,为长脚注腾出空间

问题描述 投票:0回答:1

基于此线程中的示例,我有以下代码:

import plotly.express as px
import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')

fig = go.Figure(go.Scatter(x=df['Date'], y=df['AAPL.High']))

fig.update_xaxes(rangeslider_visible=True)

note = 'NYSE Trading Days After Announcement<br>Source:<a href="https://www.nytimes.com/"">The NY TIMES</a> Data: <a href="https://www.yahoofinance.com/">Yahoo! Finance</a><br>NYSE Trading Days After Announcement<br>Source:<a href="https://www.nytimes.com/"">The NY TIMES</a> Data: <a href="https://www.yahoofinance.com/">Yahoo! Finance</a><br>NYSE Trading Days After Announcement<br>Source:<a href="https://www.nytimes.com/"">The NY TIMES</a> Data: <a href="https://www.yahoofinance.com/">Yahoo! Finance</a><br>NYSE Trading Days After Announcement<br>Source:<a href="https://www.nytimes.com/"">The NY TIMES</a> Data: <a href="https://www.yahoofinance.com/">Yahoo! Finance</a>'
fig.add_annotation(
    showarrow=False,
    text=note,
    font=dict(size=10), 
    xref='paper',
    x=0,
    yref='paper',
    y=-1.5
    )

fig.show()

注释太长,无法放入图中,因此被截断。有没有办法在图的底部添加空间以便注释适合?

python plotly visualization
1个回答
0
投票

你可以这样做:

import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')

fig = go.Figure(go.Scatter(x=df['Date'], y=df['AAPL.High']))

fig.update_xaxes(rangeslider_visible=True)

note = ('NYSE Trading Days After Announcement<br>'
        'Source:<a href="https://www.nytimes.com/">The NY TIMES</a> '
        'Data: <a href="https://www.yahoofinance.com/">Yahoo! Finance</a><br>'
  )

fig.add_annotation(
    showarrow=False,
    text=note,
    font=dict(size=10), 
    xref='paper',
    x=0,
    yref='paper',
    y=-1.5
)

fig.update_layout(
    margin=dict(l=50, r=50, t=50, b=200) 
)

fig.show()

这给出了

[![在此处输入图像描述][1]][1]

您当然可以根据自己的喜好调整大小和位置。 [1]:https://i.sstatic.net/161p2n3L.png

© www.soinside.com 2019 - 2024. All rights reserved.