调整熊猫条形图的比例

时间:2020-01-09 18:07:22

标签: python pandas python-2.7 bar-chart

因此,我打算将给定数据集中性别之间的教育差异可视化。 我按性别对员工进行分组,并用此代码对他们的years_in_education进行汇总

df1 = df[["gender","years_in_education"]] #creating a sub-dataframe with only the columns of gender and hourly wage
staff4=df1.groupby(['gender']).sum() #grouping the data frame by gender and assigning it to a new variable 'staff4'
staff4.head() #creating a visual of the grouped data for inspection

然后我使用条形图绘制这段代码的差异>>

my_plot = staff4.T.plot(kind='bar',title="Education difference between Genders") #creating the parameters to plot the graph

图形显示为>>

Graph Before Scale

但是我发现y轴的比例太高了,因为该数据中的最高就业年份是30。我打算将比例调整为0到30。我使用my_plot.set_ylim([0,30])结果是>>

Graph after adjusting scale

此图不反映第一个所示的数据。我该怎么做才能改变呢?

有什么想法吗?我还如何更改标签在y轴上的方向。

0 个答案:

没有答案
相关问题