【发布时间】:2023-02-18 12:57:48
【问题描述】:
我正在使用子图,第一个子图是热图,第二个子图是线图。绘图后,我如何知道它的绘图类型(热图或线图)?我正在使用 fig.data 来引用它的数据,是否可以从 fig.data() 获取绘图类型?感谢您的帮助。
这是我的代码:
fig = make_subplots(rows=2, cols=1, vertical_spacing=0.05,
specs=[[{"secondary_y": False}],[{"secondary_y": True}],[{"secondary_y":False}]],
subplot_titles=('DTS Long Term Heatmap for '+wellname,
'Well Production of '+wellname,
'Steam Injection of its Nearby Injectors'),
shared_xaxes=True,
row_heights=[0.6, 0.2,0.2], # new from top to bottom
)
trace0 = go.Heatmap()
data = [trace0]
fig.add_trace(trace0,row=1, col=1)
fig.add_trace(go.Scatter(
x=df.index,
y=df.values,
mode="lines",
line={"color": 'black'}, #"color": "#035593"
name='zero line',
legendgroup = '2',
showlegend=False,
),
row=row,
col=1,
secondary_y=False
)
for i, d in enumerate(fig.data):
if d.name==key_1:
legendgroup='2'
row=2
secondary_y=False
elif d.name==key_2:
legendgroup='2'
row=2
secondary_y=True
fig.add_scatter(x=[d.x[-1]], y = [d.y[-1]],
mode = 'markers+text',
text = f'{d.y[-1]:.2f}',
textfont = dict(color=d.line.color),
textposition='middle right',
marker = dict(color = d.line.color, size = 12),
legendgroup = legendgroup, #d.name,
secondary_y=secondary_y,
row=row,col=1,
showlegend=False)
【问题讨论】:
标签: python plotly plotly-python