Another thought - I also tried to do all this using small grid lines (among other things, it will help my understanding), but this is not listing properly, no doubt due to get_minorticklocs and ax.get_xgridlines. Sorry and thanks in advance ...
Jeddes
import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator, FormatStrFormatter import numpy as np fig = plt.figure(1) ax = fig.add_subplot(111) # set up axis ax.spines['left'].set_position('zero') ax.spines['right'].set_color('none') ax.spines['bottom'].set_position('zero') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') # draw curve x = np.arange(-2.5,2.5,0.01) line, = ax.plot(x, x**2) #set bounds ax.set_ybound(-1,7) # create grid ax.xaxis.set_minor_locator(MultipleLocator(0.2)) ax.yaxis.set_minor_locator(MultipleLocator(0.2)) ax.xaxis.grid(True,'minor',linewidth=2) ax.yaxis.grid(True,'minor',linewidth=2) #adjust grid on the 2s for idx,loc in enumerate(ax.xaxis.get_minorticklocs()): if loc % 2 == 0: ax.get_xgridlines()[idx].set_color('r') if loc % 1 == 0: ax.get_xgridlines()[idx].set_color('g') if loc % 0.2 == 0: ax.get_xgridlines()[idx].set_color('b') for idx,loc in enumerate(ax.yaxis.get_majorticklocs()): if loc % 2 == 0: ax.get_ygridlines()[idx].set_c('b') plt.savefig('spines3.png',dpi=300)
Geddes
source share