'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: pandas读取csv文件.py
>>作者: liu yang
>>博客: liuyang1.club
>>邮箱: liuyang0001@outlook.com
>>博客: www.cnblogs.com/liu66blog ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python
# -*- coding: utf-8 -*- 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") # 添加索引index_col=0 设置第一列为索引
df = pd.read_csv(u'xxxx.csv',encoding='utf-8',index_col=0) # print(df)
df_plot = df.plot(kind='bar', rot=0)
# 设置标题头
plt.title('学生信息', fontproperties=font)
# 第一个参数为数据排序,loc设置图例位置
plt.legend(loc=1)
plt.xlabel('姓名', fontproperties=font)
plt.ylabel('', fontproperties=font)
plt.xticks(fontproperties=font)
plt.yticks([y for y in range(0, 180, 10)],fontproperties=font)
# for x,y,z in zip(df.get('Height')):
# plt.text(-0.2,df.get("Height")[0],'%.0f'%df.get("Height")[0], ha='center', va='bottom')
# plt.text(0,df.get("Score")[0],'%.0f'%df.get("Score")[0], ha='center', va='bottom')
# plt.text(0.15,df.get("Age")[0],'%.0f'%df.get("Age")[0], ha='center', va='bottom')
# df.to_csv('数据.csv',encoding='utf-8')
# 显示
plt.show()