# -*- coding: utf-8 -*-
"""
Created on Sun Feb 25 18:48:52 2018
@author: wanping
"""
import numpy as np
import matplotlib
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import pandas as pd
data = pd.read_csv("D:/apaper/pic/s2.csv")
data.head()
songTi = matplotlib.font_manager.FontProperties(fname='C:\Windows\Fonts\simsun.ttc')
x = data.loc[:,'n_songs']
#normed=True是频率图,默认是频数图
plt.hist(x, bins=30, range=(0,100), normed=True,
weights=None, cumulative=False, bottom=None,
histtype=u'bar', align=u'left', orientation=u'vertical',
rwidth=0.8, log=False, color=None, label=None, stacked=False,
hold=None)
plt.xticks(fontproperties=songTi,fontsize=12)
plt.yticks(fontproperties=songTi,fontsize=12)
plt.xlabel('用户听歌数量(首)',fontproperties=songTi,fontsize=14)
plt.ylabel('人数占比(%)',fontproperties=songTi,fontsize=14)
# plt.legend(fontsize=12)
fig = plt.gcf()
fig.set_size_inches(7.2, 4.2)
fig.savefig('D:/apaper/pic/用户听歌数量2.png', dpi=100)
plt.show()
本次选择的是宋体
songTi = matplotlib.font_manager.FontProperties(fname='C:\Windows\Fonts\simsun.ttc')
字体选择中的字体路径查看:
打开控制面板——》找到“字体”——》选择自己想要设置的字体,右击属性查看字体路径
通过fontproperties设置字体,fontsize设置字体大小
plt.xticks(fontproperties=songTi,fontsize=12)
plt.yticks(fontproperties=songTi,fontsize=12)
plt.xlabel('用户听歌数量(首)',fontproperties=songTi,fontsize=14)
plt.ylabel('人数占比(%)',fontproperties=songTi,fontsize=14)
# plt.legend(fontsize=12)
通过以下设置图片尺寸并保存
fig = plt.gcf()
fig.set_size_inches(7.2, 4.2)
fig.savefig('D:/apaper/pic/用户听歌数量2.png', dpi=100)