解决python plot 画图过程中中文显示的最简单的方法
#!/usr/bin/python # -*- coding: <encoding name> -*- import pymssql # 引入pymssql模块 import pandas as pd import numpy as np # linear algebra import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) import matplotlib.pyplot as plt import seaborn as sns # Provides a high level interface for drawing attractive and informative statistical graphics sns.set() plt.rcParams['font.sans-serif'] = ['SimHei'] # Matplotlib中设置字体-黑体,解决Matplotlib中文乱码问题 plt.rcParams['axes.unicode_minus'] = False # 解决Matplotlib坐标轴负号'-'显示为方块的问题 sns.set(font='SimHei') from subprocess import check_output import warnings # Ignore warning related to pandas_profiling warnings.filterwarnings('ignore') conn = pymssql.connect(host='localhost', user='wonderful', password='wonderful', database='ProcreateV93',charset='GBK') sql = "select username,o_id,p_id from Oplan" df0 = pd.read_sql(sql, conn) df = pd.DataFrame(df0) des=df.describe() arr_df = pd.DataFrame(des) # print(arr_df) # arr_df.to_csv('F:/工作文档/宋春林/Oplan_describe.csv') nullsum=pd.isnull(df).sum() fig = plt.figure() # 画折线图 ax = fig.add_subplot(111) ax=df.groupby("username")["o_id"].count().plot(kind="line",title="Matches per season", marker='d',color=['blue'],figsize=(10,3)) plt.ylabel("No. of Matches") plt.show() # nullsum.to_csv('F:/工作文档/宋春林/Oplan_nullsum.csv') # 柱状图 fig = plt.figure() ax = fig.add_subplot(111) venue = df.groupby('username')['o_id'].count() gender_df = df.groupby("username", as_index=True).agg({'o_id':'count'}).rename(columns={'username': 'oid_count'}) print(gender_df.describe()) gender_df.plot.bar(figsize=(10,7)) sns.set(style="darkgrid") # sns.countplot(x='username',data=gender_df) print(gender_df) plt.xlabel('doctor_patientnumber') plt.title('doctor_patientnumber Distribution') plt.ylabel('Count') plt.show() # ax =gender_df.sort_values(ascending=False).head(10).plot.bar(figsize=(5,3)) conn.close()