To display all x values in a Plotly bar chart, you can set the x-axis to a discrete type and adjust its range. Here's how:

fig.update_layout(xaxis=dict(type='category', range=[0, len(_df)]))

This sets the x-axis to be of type 'category' and sets its range to 0 to the number of factors in the data. This will ensure all factor parameter names are displayed on the x-axis.

Here's the complete code:

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()
Plotly Subplots: Display All X Values in Bar Chart

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

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