美文网首页
python 直方图

python 直方图

作者: 似水之星 | 来源:发表于2018-05-08 00:19 被阅读0次

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)   # 直方图展示

相关文章

网友评论

      本文标题:python 直方图

      本文链接:https://www.haomeiwen.com/subject/vmgbrftx.html