如何移除plotly.subplots中第二个子图的'trace 1'标识
移除Plotly子图中箱线图的"trace 1"标识
要删除第二个子图(箱线图)上显示的"trace 1"文字,只需在创建箱线图的trace时将name属性设为空字符串,覆盖默认生成的trace名称即可。
修改后的完整代码如下:
import plotly.express as px import plotly.graph_objects as go from plotly.subplots import make_subplots import numpy as np subplot_titles = ['Histogram', 'Boxplot'] rows = 1 columns = 2 xaxis_title="full_sq" yaxis_title="Value" fig = make_subplots( rows=rows, cols=columns, subplot_titles=['Histogram', 'Boxplot'] ) trace0 = go.Histogram( x=Df["full_sq"] ) # 清空箱线图的trace名称,消除"trace 1"标识 trace1 = go.Box( x=Df["full_sq"], marker_color = 'lightseagreen', name='' ) list_trace = [trace0, trace1] for i, col in enumerate(subplot_titles): r = int(np.ceil(((i+1)/columns))) c = i%2+1 fig.add_trace(list_trace[i], row=r, col=c) fig.update_xaxes(title_text=xaxis_title, row=r, col=c) fig.update_yaxes(title_text=yaxis_title, row=r, col=c) fig.update_layout(height = 400, width = 700, showlegend = False) fig.show()
另外注意:你代码中添加的fig.add_annotation(name = False)属于无效操作,对移除trace名称没有帮助,可以直接删除这行代码。
内容的提问来源于stack exchange,提问作者Alberto Alvarez
相关产品推荐
相关产品推荐

