在您的特定情况下,我只会在 dict 中组织不同的新元素:
infos = {'price':29,
'RSI': 1.1,
'return':1.1}
然后像这样子集make_subplots() 中的字典:
fig = make_subplots(rows=3, cols=1, start_cell="top-left",
subplot_titles=("Share Price is: "+ str(infos['price']),
"RSI is: " + str(infos['RSI']),
"Portfolio Return is: " + str(infos['return'])))
为什么是字典?在定义图形后,我经常发现自己想用情节元素做一些事情。这样一来,您的新元素也可以随时用于其他目的。
剧情:
完整代码:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
infos = {'price':29,
'RSI': 1.1,
'return':1.1}
fig = make_subplots(rows=3, cols=1, start_cell="top-left",
subplot_titles=("Share Price is: "+ str(infos['price']),
"RSI is: " + str(infos['RSI']),
"Portfolio Return is: " + str(infos['return'])))
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),
row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
row=2, col=1)
fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]),
row=3, col=1)
fig.show()
f2 = fig.full_figure_for_development(warn=False)