Plotly 图表:如何隐藏图例内容

在使用 Plotly 创建图表时,有时候我们希望隐藏图例内容。可以通过将添加 trace 时图例名称设置为空字符串来实现。

例如,以下代码展示了如何使用 Plotly 创建一个子图,并在每个子图中添加一个条形图,并隐藏图例内容:

import plotly.subplots as sp
fig = sp.make_subplots(rows=len(year), cols=3, subplot_titles=[])
# , subplot_titles=feature_list
for i, _year in enumerate(year):
    _df = fig_df[fig_df['compound_name'] == _year].copy()
    fig.add_trace(
        go.Bar(x=_df['因子参数'].values, y=_df['累积净值'], name=''),
        row=i + 1, col=1,
    )

通过将 name 参数设置为空字符串 '',即可在图中隐藏图例内容。

Plotly 图表:如何隐藏图例内容

原文地址: http://www.cveoy.top/t/topic/mLJk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录