How to display Chinese in pandas plot?

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

    I think you want the characters to be the labels on the plot right?

    I just grabbed some random characters:

    In [40]: df
    Out[40]: 
       0 title
    0  0     뉵
    1  1     뉑
    2  2     늘
    3  3     度
    
    [4 rows x 2 columns]
    

    I don't think there is a way to set y_ticklabels from df.plot(), but you can set them from the returned axes object:

    In [47]: ax = df.plot(kind='barh')
    
    In [48]: ax.set_yticklabels(df['title'].str.decode('utf-8'))
    Out[48]: 
    [,
     ,
     ,
     ]
    
    In [49]: plt.draw()
    

    Here's the figure:

    enter image description here

    I'm not actually able to save the file and have the characters show up. Not sure why at the moment, but this may get you started.

提交回复
热议问题