Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何调整xlabel位置,以便与matplotlib?中的主刻度对齐;_Python_Matplotlib - Fatal编程技术网

Python 如何调整xlabel位置,以便与matplotlib?中的主刻度对齐;

Python 如何调整xlabel位置,以便与matplotlib?中的主刻度对齐;,python,matplotlib,Python,Matplotlib,旋转x_标签后,它无法与主刻度或条对齐。 这是我的密码: 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(bott

旋转x_标签后,它无法与主刻度或条对齐。

这是我的密码:

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)
您可以使用“水平对齐”选项并将文本向右对齐,例如

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()
还有这个


谢谢你的回答