python - Set scale of axis in plot using matplotlib -


i unable scale y-axis. code follows:

import matplotlib.pyplot pt import numpy np fig = pt.figure() ax = fig.add_subplot(111) sample = 20 x=np.arange(sample) y=10*np.sin(2*np.pi*x/20) pt.plot(x,y) pt.show() 

the y axis has scale of 5. i'm trying make 1. the output snapshot

you can using set_yticks way:

import matplotlib.pyplot plt import numpy np fig = plt.figure() ax = fig.add_subplot(111) sample = 20 x=np.arange(sample) y=10*np.sin(2*np.pi*x/20)  ax.plot(x,y) ax.set_yticks(np.arange(min(y), max(y)+1, 1.0)) # setting ticks ax.set_xlabel('x') ax.set_ylabel('y') fig.show() 

which produces image wherein y-axis has scale of 1.

enter image description here


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -