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 轴值都可见。
一种可能的解决方案是将刻度模式设置为线性,这意味着 Plotly 将为每个类别显示一个刻度。您还可以调整刻度角度和字体大小以使标签更明显。例如,您可以将以下行添加到代码中:
fig.update_xaxes(tickmode="linear", tickangle=-45, tickfont_size=10)