Display non ascii (Japanese) characters in pandas plot legend

前端 未结 1 1627
臣服心动
臣服心动 2021-01-06 00:41

If I do this:

import pandas as pd
pd.DataFrame( data=nr.random( (2,2) ), columns=[u\'é\',u\'日本\'] ).plot()

Result:

相关标签:
1条回答
  • 2021-01-06 01:21
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    import matplotlib.font_manager as font_manager
    
    df = pd.DataFrame( data=np.random.random( (2,2) ), columns=[u'é',u'日本'] )
    ax = df.plot()
    legend = ax.legend()
    font = font_manager.FontProperties(fname='/Users/user/Downloads/IPAfont00303/ipag.ttf')
    
    for text in legend.texts:
        text.set_font_properties(font)
    
    plt.show()
    
    0 讨论(0)
提交回复
热议问题