Abhishek
Abhishek

Reputation: 3066

Matplotlib y-axis values not properly shown

I have a matplolib bar chart as follows:

x=np.arange(13) 
y=[0,90,94,78,0,90,80,88,83,0,0,60,0]
fig=Figure()
fig.set_figheight(15)
fig.set_figwidth(30)
fig.set_facecolor('white')
ax=fig.add_subplot(111)
width=0.7
ax.bar(x, y, width)
ax.set_xlabel('Semesters', fontsize=25)
ax.set_ylabel('Scores', fontsize=25)
ax.set_xticks(x+0.35)
ax.set_xticklabels(('F1','F2','S','Grade','F1','F2','S','Grade','SEM 1','F1','F2','S','Grade'), fontsize=25, rotation='vertical')
ax.set_yticklabels(y,fontsize=25)

Here the plot shows up well but the y-axis shows the values of y instead of the range(0-90). It shows values 0,90,94,78,0,90 and then stops. Where am i going wrong? Also the x label doesn't show up any longer once i changed my x ticks to vertical!

Upvotes: 2

Views: 4672

Answers (1)

Sergio Losilla
Sergio Losilla

Reputation: 860

This is the line that is wrong:

ax.set_yticklabels(y,fontsize=25)

It is setting the labels to the list y, which you declared earlier. If you comment it out, it will put the correct labels. You will still need to change the font size.

And next time, please put the complete code so we don't have to figure out which modules must be imported and how to do the plot...

Upvotes: 4

Related Questions