pandas字体调整
#!/usr/bin/python # -*- coding: <encoding name> -*- import matplotlib.pyplot as plt import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) import pymssql # 引入pymssql模块 import seaborn as sns # Provides a high level interface for drawing attractive and informative statistical graphics from matplotlib.font_manager import FontProperties from pylab import * import matplotlib.pyplot as plt import seaborn as sns plt.rcParams['font.sans-serif'] = ['SimHei'] # Matplotlib中设置字体-黑体,解决Matplotlib中文乱码问题 plt.rcParams['axes.unicode_minus'] = False # 解决Matplotlib坐标轴负号'-'显示为方块的问题 sns.set(font='SimHei') # Seaborn中设置字体-黑体,解决Seaborn中文乱码问题 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,COUNT(DISTINCT o_id) AS Oidcount from Oplan GROUP BY username order by Oidcount desc " df0 = pd.read_sql(sql, conn) df = pd.DataFrame(df0) #orient='h'表示是水平展示的,alpha表示颜色的深浅程度 #设置y轴、X轴的坐标名字与字体大小 ax=sns.barplot(x=df.username.values,y=df.Oidcount.values,palette=sns.color_palette('YlGn')) # ax.set_xticklabels(rotation = 45,fontsize = 15) # 放大横轴坐标并逆时针旋转45° # ax.set_yticklabels(labels = [0,500,1000,1500,2000,2500,3000,3500],fontsize = 15) # 放大纵轴坐标 plt.xlabel('医生',fontsize=12) plt.ylabel('患者数',fontsize=12)
# 调整x轴的字体 plt.xticks(size = 8)
# 调整y轴字体 plt.yticks(size = 10) plt.rcParams['xtick.direction'] = 'out' plt.rcParams['ytick.direction'] = 'inout' plt.tight_layout() #设置X轴的各列下标字体是水平的 # plt.xticks(rotation='horizontal') #设置Y轴下标的字体大小 plt.show()