如何在matplotlib中设置图形的增量
我在用Python的matplotlib库生成和绘制图表,但我不知道怎么让y轴不以e
的倍数来表示。现在y轴上的数值在0.01到0.05之间,顶部显示的是+2.288e1,这实际上对应的是大约20的“合理”值。我该怎么做才能让matplotlib不使用这种表示法呢?
def plotTime(a, aName, b, bName, graphTitle):
print a
print b
if max(a) >= max(b):
plt.axhline(max(a), color='r')
else:
plt.axhline(max(b), color='r')
if max(a) >= max(b):
plt.axhline(max(a), color='r')
else:
plt.axhline(max(b), color='r')
a, = plt.plot(a)
b, = plt.plot(b)
plt.legend([a, b], [aName, bName])
plt.suptitle(graphTitle, fontsize=20)
plt.ylabel('Time (min)')
plt.xlabel('xth file created')
plt.show()
return
1 个回答
0
你可以通过设置坐标轴的限制来进行调整,使用的函数是 ticklabel_format:
plt.ticklabel_format(axis='y', style='plain', scilimits=(-2,2))
你也可以尝试另一种解决方法,添加以下内容:
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
还可以尝试将显示方式改为竖着的,这样可以避免文字重叠(不过这只是个建议)。
plt.yticks(rotation='vertical')