Reputation: 2704
I am new to matplotlib and working on graphs, when i use plt.ticks it do not show yticks provided by me as np array instead it shows same old graph values at y axis.
I tried answers on stack overflow of questions related to this but still not working.
import matplotlib.pyplot as plt
import numpy as np
pop=np.random.randint(low=2.1,high=6.5,size=10)
pop.sort()
year=np.arange(1950,2050,10)
plt.plot(year,pop)
plt.xlabel('Year')
plt.ylabel('Population')
plt.title('World Population')
plt.yticks=(np.arange(0,5,1))
plt.show()
Upvotes: 4
Views: 4693
Reputation: 16730
The issue is this line:
plt.yticks=(np.arange(0,5,1))
plt.yticks
is a function that is used to set the Y ticks of the plot.
In your code, you assign to plt.yticks
your tick values, which has actually no effect.
You should rather call plt.yticks
with the tick values as first parameter, as follows:
plt.yticks(np.arange(0,5,1))
Reference from Matplotlib's documentation:
matplotlib.pyplot.yticks(ticks=None, labels=None, **kwargs)
Get or set the current tick locations and labels of the y-a
Call signatures:
yticks(ticks, [labels], **kwargs) # Set locations and labels
Upvotes: 3