这是一个老话题,但我时不时地会遇到这个问题,并制作了这个函数。非常方便:
import matplotlib.pyplot as pp
import numpy as np
def resadjust(ax, xres=None, yres=None):
"""
Send in an axis and I fix the resolution as desired.
"""
if xres:
start, stop = ax.get_xlim()
ticks = np.arange(start, stop + xres, xres)
ax.set_xticks(ticks)
if yres:
start, stop = ax.get_ylim()
ticks = np.arange(start, stop + yres, yres)
ax.set_yticks(ticks)
像这样控制勾号的一个注意事项是,在添加一行之后,用户不再享受max scale的交互式自动图像更新。那就去吧
gca().set_ylim(top=new_top) # for example
并再次运行resadjust函数。