How to display Chinese in pandas plot?

后端 未结 5 2199
轮回少年
轮回少年 2020-12-21 03:34

Here, I have a plot work to do with pandas, like this :

most_active_posts.plot(x = \'title\',y = \'active_span\',kind = \'barh\')

mos

5条回答
  •  情书的邮戳
    2020-12-21 04:11

    My work-around is like this:

    import pandas as pd
    import matplotlib.pyplot as plt
    import matplotlib.font_manager as fm
    font = fm.FontProperties(fname='c:\\windows\\fonts\\simsun.ttc')  # speicify font
    ax = most_active_posts.plot(x = 'title',y = 'active_span',kind = 'barh')
    ax.set_xticklabels(most_active_posts['title'].str.decode('utf-8'), fontproperties=font)
    plt.show()
    

    Basically, you need to specify a valid font for Chinese characters.

提交回复
热议问题