python - 图例显示中文

时间:2023-03-09 07:54:06
python - 图例显示中文
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 30 13:24:00 2015 @author: jx_luo
""" from pandas import DataFrame, Series import pandas as pd
import numpy as np import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager path=r'D:\Users\jx_luo\Documents\wait.txt'
frame=pd.read_csv(path,header=False,sep='\t') f=pd.pivot_table(frame, index='createdate',values='wait',columns='paycategory' ,aggfunc=np.sum) #ax = f.plot(subplots=True,figsize=(12,20),grid=False, title='wait ') ax=f.plot() legend = ax.legend()
font = font_manager.FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf") for text in legend.texts:
text.set_font_properties(font) plt.show()