我正在使用matplotlib.pyplote模块绘制直方图,我想知道如何才能强制y轴标签只显示整数(例如0、1、2、3等),而不是小数(例如0、0.5、1.1.5、1.5、2等等)。
def doMakeChart(item, x):
if len(x)==1:
return
filename = "C:\Users\me\maxbyte3\charts\\"
bins=logspace(0.1, 10, 100)
plt.hist(x, bins=bins, facecolor='green', alpha=0.75)
plt.gca().set_xscale("log")
plt.xlabel('Size (Bytes)')
plt.ylabel('Count')
plt.suptitle(r'Normal Distribution for Set of Files')
plt.title('Reference PUID: %s' % item)
plt.grid(True)
plt.savefig(filename + item + '.png')
plt.clf()
发布于 2018-03-23 17:33:42
另一种方法是:
from matplotlib.ticker import MaxNLocator
ax = plt.figure().gca()
ax.yaxis.set_major_locator(MaxNLocator(integer=True))
https://stackoverflow.com/questions/-100003680
复制相似问题