Python数据可视化之matplotlib实践 源码 第二篇 精进 第五章
图 5.1 import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter x =np.linspace(0.5, 3.5, 100 ) y = np.sin(x) fig =plt.figure(figsize=(8, 8 )) ax =fig.add_subplot(111 ) ax.xaxis.set_major_locator(MultipleLocator( 1.0 )) ax.yaxis.set_major_locator(MultipleLocator( 1.0 )) ax.xaxis.set_minor_locator(AutoMinorLocator( 4 )) ax.yaxis.set_minor_locator(AutoMinorLocator( 4 )) def minor_tick(x, pos): if not x%1.0 : return "" return " %.2f " % x ax.xaxis.set_minor_formatter(FuncFormatter(minor_tick)) ax.tick_params( " y " , which= '