[Python Study Notes]pandas.DataFrame.plot()函数绘图
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' >>文件: pandas作图.py >>作者: liu yang >>博客: liuyang1.club >>邮箱: liuyang0001@outlook.com >>博客: www.cnblogs.com/liu66blog ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python # -*- coding: utf-8 -*- import sys, os import matplotlib import pandas as pd import numpy as np import matplotlib.pyplot as plt # 定义要使用的字体,防止出现中文乱码 font=matplotlib.font_manager.FontProperties(fname=r"C:\Windows\Fonts\Deng.ttf") def bar1(): df=pd.DataFrame( {'Height':[166,167,177,120], 'Age':[23,23,24,25], 'Score':[80,100,67,60] }, # 定义数据显示的顺序 columns=['Height','Score','Age'], index=['liu','shi','song','ma'] ) # kind为画图类型,rot为旋转角度 df_plot=df.plot(kind='bar',rot=0) # 设置标题头 plt.title('学生信息',fontproperties=font) # 第一个参数为数据排序,loc设置图例位置 plt.legend(df.columns,loc=1) plt.xlabel('姓名',fontproperties=font) plt.ylabel('',fontproperties=font) plt.xticks() plt.yticks([y for y in range(0,180,10)]) for i in range(0,4): plt.text(i-0.18,df.get("Height")[i],'%.0f'%df.get("Height")[i], ha='center', va='bottom') plt.text(i,df.get("Score")[i],'%.0f'%df.get("Score")[i], ha='center', va='bottom') plt.text(i+0.15,df.get("Age")[i],'%.0f'%df.get("Age")[i], ha='center', va='bottom') # 显示 plt.show() if __name__ == '__main__': bar=bar1()
最有用的语言,除了English,其次可能是Python