只有偶数索引定位的条形图才会在条形图中显示 x 轴值

问题描述 投票:0回答:1
trace = go.Bar(x=list(month_values.keys()), y=list(month_values.values()))
    # Defining layout with title, x-axis, and y-axis labels
    layout = go.Layout(
        title='Months',
        xaxis=dict(title='Month'),
        yaxis=dict(title='Count'),
        title_x = 0.5,
        title_y = 0.87
    )

    # Creating figure object that includes both trace and layout
    fig = go.Figure(data=[trace], layout=layout)

    # Displaying the chart
    iplot(fig)

我使用上面的代码片段使用 Plotly Library 创建了条形图,但 x 轴值仅对于偶数索引条形可见。

帮助我让所有条形的 x 轴值都可见。

python pandas matplotlib plotly visualization
1个回答
0
投票

一种可能的解决方案是将刻度模式设置为线性,这意味着 Plotly 将为每个类别显示一个刻度。您还可以调整刻度角度和字体大小以使标签更明显。例如,您可以将以下行添加到代码中:

fig.update_xaxes(tickmode="linear", tickangle=-45, tickfont_size=10)
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.