如何调整Matplotlib中的x轴标签位置,以与主刻度对齐?

2024-05-29 04:09:57 发布

您现在位置:Python中文网/ 问答频道 /正文

在旋转xÈU标签后,它无法与主刻度或条对齐。 as this picture showed

这是我的密码:

x = df3[df3['Database'] == 'aminoglycoside'].Resistance_gene
y = df3[df3['Database'] == 'aminoglycoside'].Percent
plt.figure(figsize=(30,15))
plt.xticks(fontsize=20,rotation=45)
plt.margins(0.05)
plt.subplots_adjust(bottom=0.15)
plt.bar(x,y,width=0.5)

Tags: 密码plt标签databasefigurepercentgene刻度
1条回答
网友
1楼 · 发布于 2024-05-29 04:09:57

您可以使用水平对齐选项并将文本向右对齐,例如

import matplotlib.pyplot as plt
plt.plot(range(5))
plt.xticks(range(5),['some','long','labels','even','very long ones'],rotation=45,fontsize=20,horizontalalignment='right')
plt.show()

拿着这个

and got this

相关问题 更多 >

    热门问题