mac笔记本的直方图的标题中文无乱码
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties
#设置字体,确认mac电脑的字体位置是'/Library/Fonts/Songti.ttc'
font = FontProperties(fname='/Library/Fonts/Songti.ttc')
# 参数依次为list,标题,X轴标签,Y轴标签,XY轴的范围
def draw_hist(myList,Title,Xlabel,Ylabel,Xmin,Xmax,Ymin,Ymax):
plt.hist(myList,100)
plt.xlabel(Xlabel)
plt.xlim(Xmin,Xmax)
plt.ylabel(Ylabel)
plt.ylim(Ymin,Ymax)
plt.title(Title, fontproperties = font)
plt.show()
#partDataId和partDataTableId为list数据类型
draw_hist(partDataId, '用户体检次数统计', 'value', 'number', 0, 350, 0.0, 8) # 直方图展示
draw_hist(partDataTableId, '体检项目频次统计', 'value', 'number', 0, 350, 0.0, 8) # 直方图展示