我想在位置和该位置存在的公司数量之间绘制图表。
# split data on basis of group
location_group = fortune_df.groupby('Location')
# pick top 10 location with maximum location
location_withmax_no_of_companies = location_group.size().sort_values(ascending = False)[:10]
Location
New York, NY 72
Houston, TX 44
Atlanta, GA 23
Chicago, IL 22
Dallas, TX 16
St. Louis, MO 14
San Francisco, CA 11
Cleveland, OH 11
San Jose, CA 10
Columbus, OH 10
dtype: int64
lpos = np.arange(10)
plt.xticks(lpos,location_withmax_no_of_companies)
plt.bar(lpos,location_withmax_no_of_companies)
我想要位置的名称而不是数字(x轴),但没有得到如何在x轴上给定名称的方法。任何线索都将有所帮助。
您可以使用pandas进行绘图Series.plot.bar
:
location_withmax_no_of_companies.plot.bar()
或更改location_withmax_no_of_companies
为location_withmax_no_of_companies.index
按指数变化的标签Series
:
plt.xticks(lpos,location_withmax_no_of_companies.index)
如果需要,还旋转标签:
plt.xticks(lpos,location_withmax_no_of_companies.index, rotation=90)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句