代码:
from matplotlib import pyplot as plt
import random
x = range(0,120)
y = [random.randint(20,35) for i in range(120)]
#图片大小
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)
#调整x轴的刻度
_x= list(x)[::10]
_xtick_labels= ["hello,{}".format(i) for i in _x]
plt.xticks(x,_xtick_labels)
plt.show
报错:
The number of FixedLocator locations (13), usually from a call to set_ticks, does not match the number of ticklabels (12).
解决办法:
plt.xticks(x,_xtick_labels) 这句x ,_xtick_labels长度不一致造成的
改成:plt.xticks(_x,_xtick_labels)
本文介绍了一个在使用Matplotlib进行绘图时遇到的问题,即由于`plt.xticks()`中输入的x值和标签列表长度不一致导致的错误。解决办法是调整函数调用为`plt.xticks(_x,_xtick_labels)`,确保两者长度匹配。
683

被折叠的 条评论
为什么被折叠?



