python - matplotlib locator_params or set_major_locator not working -


i trying reduce number of axis ticks in subplots (each axis different values, can't set ticks manually), other answers such this or this don't work. syntax creating figure standard, follows:

fig = plt.figure(figsize=(7,9)) ax = fig.add_subplot(8,2,i+1) # plotting in larger loop, don't think there wrong loop, because else (axis limits, labels, plotting itself...) works fine. 

and reduce number of yticks, tried

ax = plt.locator_params(nbins=4, axis='y') 

which raised error typeerror: set_params() got unexpected keyword argument 'nbins'

and tried

ax.yaxis.set_major_locator(plt.maxnlocator(4)) 

which gave error attributeerror: 'nonetype' object has no attribute 'yaxis'

i don't understand why subplot considered nonetype. suspect core of problem, examples saw have same structure, i.e.

fig = plt.figure() ax = fig.add_subplot(111) ax.yaxis.set_major_locator(plt.maxnlocator(4)) 

and should work. why ax nonetype?

the problem line:

ax = plt.locator_params(nbins=4, axis='y') 

locator_params not return axes instance (in fact doesn't return anything), on line reassigning ax none.

i think want change to:

ax.locator_params(nbins=4, axis='y') 

and should work ok.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -