recent_grads["ShareMen"] = recent_grads["Men"]/recent_grads["Total"] # Create a new column named "ShareMen" , the value is column 'Men' dedide "Total"
 

  Arts_column = pd.DataFrame(recent_grads[recent_grads["Major_category"]=="Arts"]) # Create a new DataFrame named Art_column, and the value is all the data with the Major named "Arts"

  Arts_fig = plt.figure(figsize=(8,8)) # Create a figure with 8*8 inch

  Arts_plot = Arts_fig.add_subplot(1,1,1) # Create a plot

  locs = np.arange(len(Arts_column["Major"])) #Return evenly spaced values within a given interval, the interval is the length of Arts_column["Major"]

  offset_locs = locs + 0.35 

  Arts_plot.set_xticks(offset_locs) 

  Arts_plot.set_xticklabels(Arts_column["Major"].tolist(),rotation = 90)

  bar_1 = Arts_plot.bar(locs,Arts_column["ShareMen"].tolist(),0.35) #plot.bar(Bar location, Bar value, bar width)

  bar_2 = Arts_plot.bar(offset_locs,Arts_column["ShareWomen"].tolist(),0.35,color = "green")

  plt.legend((bar_1,bar_2),("ShareMen","ShareWomen"),loc = "upper left")

  Arts_plot.grid(b="on",which = "major",axis = "both")

posted on 2016-10-18 02:37  阿难1020  阅读(470)  评论(0编辑  收藏  举报