gpt4 book ai didi

python - 将 x 轴刻度标签向左移动一位

转载 作者:行者123 更新时间:2023-11-28 20:16:18 25 4
gpt4 key购买 nike

<分区>

我正在制作条形图,我想将 x 轴刻度标签向左移动一个位置。这是情节的代码:

matplotlib.rcParams.update(matplotlib.rcParamsDefault)
plt.style.use(['seaborn-white', 'bmh'])

fig1, ax = plt.subplots()

palette = ['#2a5495', '#07a64c', '#e979ad', '#d88432', '#2a5495',
'#b7040e', '#82c5db', '#b9c09b', '#cd065d', '#4b117f']

x = np.array(df.index)
y = np.array(df.loc[:, 2015])

width = 1.0
lefts = [x * width for x, _ in enumerate(y)]
ax.bar(left = lefts, height = y, width = width, tick_label = x, color = palette, label = ranked_univs)

ax.axis(ymin = 0, ymax = 200, xmin = -0.5, xmax = 9.5)
ax.tick_params(axis='x', which='major', labelsize=8)
ax.set_xticklabels(ax.xaxis.get_majorticklabels(), rotation=45)

fig1.tight_layout()
plt.show()

这是条形图:

enter image description here

有什么线索吗?

25 4 0