设置 xlabel matplotlib python

set xlabel matplotlib python

有个matplotlib问题想请教

在下图中,我想要 'enlarge' 标签,而不是范围 (0,1,0.2),我想要范围 (0,1,0.01) 并可视化每一步 (0.01 , 0.02, 0.03, ...).

这是我的剧情代码:

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

fig, ax = plt.subplots(figsize=(12, 6),dpi=800)
count = (frecuency/len(acousticness))
width = 0.005
print(type(frequency))    

ax.set_ylim([0, 3])
xlim=np.arange(0,1,0.01)
my_colors = 'rgbkymc'
plt.bar(frecuency.index, frecuency,width,edgecolor="Orange",color=my_colors)
plt.ylim(0, 5)
plt.xlim(xlim)
# Add labels
plt.title('Histogram of Acousticness')
plt.xlabel('Acousticness')
plt.ylabel('Frecuency')

此外,plt.xlim(xlim) 上发生错误:

ValueError:要解压的值太多(预期为 2 个)

xlim=np.arange(0,1,0.01)
plt.xlim(xlim)

您调用了错误的方法。您可能想将第二行更改为

plt.xticks(xlim)

让它发挥作用。 (那么最好也更改变量名称。)