Reputation: 198
I am unable to scale the y-axis. My code is as follows:
import matplotlib.pyplot as pt
import numpy as 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 to make it 1.
Upvotes: 0
Views: 8855
Reputation: 9363
You can do so using set_yticks
this way:
import matplotlib.pyplot as plt
import numpy as 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 the ticks
ax.set_xlabel('x')
ax.set_ylabel('y')
fig.show()
Which produces this image wherein y-axis
has a scale of 1.
Upvotes: 2