How to display Chinese in pandas plot?

后端 未结 5 2195
轮回少年
轮回少年 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:15

    if you use pandas, you can use get_xticklabels to get labels and then set them with set_xticklabels.

    import matplotlib.font_manager as mfm
    import matplotlib.pyplot as plt
    
    font_path = "/System/Library/Fonts/STHeiti Light.ttc"
    prop = mfm.FontProperties(fname=font_path)
    df = pd.read_csv("data.txt"]
    figure, ax = plt.subplots(figsize=(12, 4))
    tmp = df.boxplot(by='shop', column='buy', ax=ax)
    ax.set_xticklabels(tmp.get_xticklabels(), fontproperties=prop)
    plt.show()
    

提交回复
热议问题