Matplotlib y轴值未正确显示

时间:2020-12-08 20:15:27

I have a matplolib bar chart as follows:

我有一个matplolib条形图如下:

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!

这里的图表很好地显示,但y轴显示y的值而不是范围(0-90)。它显示值0,90,94,78,0,90然后停止。我哪里错了?一旦我将x刻度改为垂直,x标签就不再显示了!

1 个解决方案

#1


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.

它将标签设置为您先前声明的列表y。如果您将其注释掉,它会放置正确的标签。您仍然需要更改字体大小。

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...

下次,请填写完整的代码,这样我们就不必弄清楚必须导入哪些模块以及如何绘制图...

#1


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.

它将标签设置为您先前声明的列表y。如果您将其注释掉,它会放置正确的标签。您仍然需要更改字体大小。

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...

下次,请填写完整的代码,这样我们就不必弄清楚必须导入哪些模块以及如何绘制图...