绘图:如何在 y 轴上分隔(带大括号)几个间隔

Plotly: How can I delimiter (with braces ) several intervals on the y-axis

提问人:Eli o 提问时间:11/3/2023 最后编辑:Jason AllerEli o 更新时间:11/3/2023 访问量:22

问:

我正在尝试根据 y 值的不同间隔向 y 轴添加注释,并用大括号或括号制作分隔符。

这是我所拥有的:

在 y 轴中,我放置了不同对象的 ID,并进行了注释(“Campo”、“Grupo”或“Cumulo”)以显示每个 ID 属于哪个子类别。但我想用括号或大括号分隔每个子组。

例如,前三个 ID 属于子组“Campo”。如何分隔它?

我的代码:

y_annotation = ['Campo','Grupo','Cumulo']

intervals = {'Campo':[0,len(id_campo)-1],
             'Grupo':[len(id_campo), len(id_campo)+len(id_grupo)-1],
             'Cumulo':[len(id_campo)+len(id_grupo),len(id_campo)+len(id_grupo)+ len(id_cumulo)-1]}

fig = go.Figure(data=go.Heatmap(
        z=dff['Color'],
        x=dff['lbt'],
        y=dff['y'],
         zmax=1 , zmin=0, 
        hovertemplate='lbt:%{x}<br>ID:%{y}<br>Index g-r:%{z}',
        showlegend=False,
        name='',
        colorscale=[[0, 'darkblue'],    
                [0.3, "blue"],
                [0.6, "white"],
                [0.8, "red"],
                [1, "darkred"],
                ],        
        colorbar=dict(
        len= 1.1,
        x=1, y=0.5,   
        title="g-r",
        titleside="top",
        tickmode="array",
        tickvals=[0,0.3,0.6,0.8,1 ],
        ticktext=['0',"0.3","0.6", "0.8",'1'],
        ticks="outside"
    )))
                                 
    

fig.update_xaxes(autorange="reversed",        
    )
fig.update_layout(
   
        xaxis=dict(
        title_text="Lbt[Gyrs]",
        #ticktext=["0", "2", "4", "6"],
        tickvals=np.array([0,2,4,6,8,10,12]),
        titlefont=dict(size=15),
             ),
    yaxis=dict(
        title_text="IDs",
        ticktext=dff['ID'].unique(),
        tickvals=np.arange(0,len(dff['ID'].unique()),1),
        
        tickmode="array",
        titlefont=dict(size=15),
             ),
))

# make room for annotations
fig.update_layout(margin=dict(l=150))

for k in intervals.keys():
    fig.add_annotation(dict(font=dict(color="green",size=14),
                            #x=x_loc,
                            x=-0.28,
                            y=(intervals[k][0]+intervals[k][1])/2,
                            showarrow=False,
                            text="<i>"+k+"</i>",
                            textangle=0,
                            xref="paper",
                            yref="y"
                           ))

我该怎么做?

绘图 热图

评论

0赞 r-beginners 11/3/2023
目前没有可用的特殊方法,因此您必须在正在创建的字符串注释中设计自己的方法。例如,您可以将 ID 放在开始 ID 之前和最后一个 ID 之后。[]

答: 暂无答案