import plotlysubplots as sp fig = spmake_subplotsrows=lenyear cols=3 subplot_titles= # subplot_titles=feature_list for i _year in enumerateyear _df = fig_dffig_dfcompound_name == _yearcopy figadd_tra
要显示所有x值,可以将x轴设置为离散型并调整其范围,例如:
fig.update_layout(xaxis=dict(type='category', range=[0, len(_df)]))
这将把x轴设置为离散类型,并将其范围设置为0到数据中因子参数的数量。这样,所有因子参数的名称都将显示在x轴上。完整的代码如下:
import plotly.subplots as sp
fig = sp.make_subplots(rows=len(year), cols=3, subplot_titles=[])
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=_year),
row=i + 1, col=1,
)
fig.update_layout(xaxis=dict(type='category', range=[0, len(_df)]))
fig.show()
原文地址: https://www.cveoy.top/t/topic/bjbV 著作权归作者所有。请勿转载和采集!