R P Pranav
R P Pranav

Reputation: 1

Is there a way to change scale of y axis in python plot?

Currently i am able to generate this plot to calculate number of people using applications, but i am getting y axis values as in decimals ,where in people cannot be in decimals. how can i change this ?

df_pivot=pd.pivot_table(df_removed1,index=['Module'],columns=['Date'], aggfunc='size').plot(kind='bar',grid=True)
plt.xticks(weight='bold')
plt.xlabel(App_req,size="25",weight='bold')
plt.title(grph_title)

this is the code i am using to plot graph for my data

current output

Upvotes: 0

Views: 358

Answers (2)

Luigi Matera
Luigi Matera

Reputation: 23

You can try to give yticks() the integers generated by range():

plt.yticks(range(0,2))

Otherwise you can try:

from matplotlib.ticker import MaxNLocator
plt.yaxis.set_major_locator(MaxNLocator(integer=True))

Upvotes: 1

Alessandro Togni
Alessandro Togni

Reputation: 885

You can try using plt.set_yticks()

docs here: https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.set_yticks.html

Upvotes: 0

Related Questions