import matplotlib.pyplot as plt
from matplotlib.font_manager import FontManager
from pylab import mpl
import subprocess
def get_matplot_zh_font():
fm = FontManager()
mat_fonts = set(f.name for f in fm.ttflist)
output = subprocess.check_output('fc-list :lang=zh -f "%{family}n"', shell=True).decode('utf-8')
zh_fonts = set(f.split(',', 1)[0] for f in output.split('n'))
available = list(mat_fonts & zh_fonts)
return available
available=get_matplot_zh_font()
print(available)
def conf_zh(font_name):
from pylab import mpl
mpl.rcParams['font.sans-serif'] = [font_name]
mpl.rcParams['axes.unicode_minus'] = False
conf_zh("Noto Sans CJK JP")#来自于available中的字体
labels = ['<5','5-9','10-14', '15-19', '20-24', '25-29', '30-34','>34']
data1 = [0, 1805, 10777, 7036, 1858, 424, 73, 27]
data2 = [1, 1322, 9614, 8386, 3383, 1118, 402, 252]
x=np.arange(len(labels))
total_width=0.8
n=2
width=total_width/n
x = x - (total_width - width) / 2
plt.bar(x, kgclue_data, width=width,fc='r',tick_label=labels,label='data1',align='edge')
plt.bar(x+width, nlpcc_data, width=width,fc='b',tick_label=labels,label='data2',align='edge')
plt.xlabel("句子长度")
plt.ylabel("样本数量")
plt.legend()
plt.show()