使用多个类型/类别绘制子地块,但在多个子地块中需要相同的线条和图例

2024-10-04 11:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

上面我应该有两个图例,一个用于A型,另一个用于B型 我试过了,但得到了4个传奇

这是我的数据框 enter image description here

这些都是我到目前为止设法搞到的阴谋 enter image description here

代码如下

wellfilter=['Type-A','Type-B']
DFPLOTtemp=DFPLOT
fig = make_subplots(
    rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.05, horizontal_spacing=0.1)

for wellfilter, DFPLOTtemp in DFPLOTtemp.groupby('Type'):
    fig.add_trace(go.Scatter(x=DFPLOTtemp.DATE, y=DFPLOTtemp.Col_A,mode="lines+markers",
                              name=wellfilter,connectgaps=False),row=1, col=1)
    fig.add_trace(go.Scatter(x=DFPLOTtemp.DATE, y=DFPLOTtemp.Col_C,mode="markers",
                             name=wellfilter,connectgaps=False),row=2, col=1)
# -----
fig.update_layout(height=800, width=1200,
                  title_text="Subplot_TEST")
fig.update_xaxes(showline=True, linewidth=2, linecolor='black', mirror=True)
fig.update_yaxes(showline=True, linewidth=2, linecolor='black', mirror=True,rangemode="tozero")

pyo.plot(fig,filename='ploty_test.html')

Tags: addtruegodatemodetypefigtrace