简体   繁体   English

如何在plotly python中的add_shape上使add_traces中的文本可见

[英]How to make text visible in add_traces over the add_shape in plotly python

I have a plot having rectangles and text.我有一个包含矩形和文本的图。 I see that my text in the add_traces is not visible.我看到我在 add_traces 中的文本不可见。 But when I tried to remove the fill color in add_shape(), I can see the traces.但是当我尝试在 add_shape() 中移除填充颜色时,我可以看到痕迹。 Here is a sample code:这是一个示例代码:

for row in df.index:
    fig.add_shape(type="rect",x0=start, y0=1, x1=start+df[score][row], y1=1.5,line=dict(color='green',),fillcolor='green',)
    start=start+df['score'][row]+2
fig.add_trace(go.Scatter(x=np.cumsum(list(df['score']+2))-df['score'][0],y=[1.25]*df.shape[0],mode="text",textfont=dict(family="sans serif",size=10,color="yellow"),
    text=list(df['Exon_Number']), showlegend=False,textposition='top center',))

How do I make the text visible by displaying the traces over the rectangle shape?如何通过在矩形形状上显示痕迹来使文本可见?

Many thanks in advance!提前谢谢了!

Answering my own questions hoping it helps anyone in the future.回答我自己的问题,希望它对将来的任何人有所帮助。

In the add_shape function, we can send the layer back using layer='below'.在 add_shape 函数中,我们可以使用 layer='below' 将图层发回。 Due to this, the text traces would be visible.因此,文本痕迹将是可见的。

for row in df.index: fig.add_shape(type="rect",x0=start, y0=1, x1=start+df[score][row], y1=1.5,layer = 'below',line=dict(color='green',),fillcolor='green',) start=start+df['score'][row]+2 fig.add_trace(go.Scatter(x=np.cumsum(list(df['score']+2))-df['score'][0],y=[1.25]*df.shape[0],mode="text",textfont=dict(family="sans serif",size=10,color="yellow"), text=list(df['Exon_Number']), showlegend=False,textposition='top center',))对于 df.index 中的行: fig.add_shape(type="rect",x0=start, y0=1, x1=start+df[score][row], y1=1.5,layer = 'below',line=dict (color='green',),fillcolor='green',) start=start+df['score'][row]+2 fig.add_trace(go.Scatter(x=np.cumsum(list(df[' score']+2))-df['score'][0],y=[1.25]*df.shape[0],mode="text",textfont=dict(family="sans serif",size= 10,color="yellow"), text=list(df['Exon_Number']), showlegend=False,textposition='top center',))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM