3

I am trying to draw out some graph using Python Seaborn, but it looks like it cannot read the data names. Data is in Korean.

So this happens...

import seaborn as sns
import matplotlib.pyplot as plt

a = ['전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도']

df = pd.DataFrame(a, columns=['province'])
sns.catplot(x='province', kind='count', data=df)
plt.show()

Graph

How can I fix this?

Peter
  • 97
  • 1
  • 8

1 Answers1

3

This is an issue with fonts. Just set your font to something that supports CJK (Chinese-Japanese-Korean) characters, e.g. 'Noto Sans CJK JP'. Then, just use sns.set(font=...) to set it:

import pandas as pd
import seaborn as sns 

# : setting the font  
sns.set(font='Noto Sans CJK JP') 

a = ['전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '전라북도', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '서울', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도', '경기도'] 

df = pd.DataFrame(a, columns=['province']) 
sns.catplot(x='province', kind='count', data=df)

resulting in:

enter image description here

See here to get a list of the fonts available in your system that Matplotlib (and hence Seaborn) can find.

norok2
  • 25,683
  • 4
  • 73
  • 99
  • It still doesn't work on mine... I'm using PyCharm. – Peter Sep 30 '19 at 18:01
  • @Peter It should work with PyCharm too. Do you get any error message? It may be a good idea to run it from a IPython console to see if it works there and/or what error you get. – norok2 Sep 30 '19 at 19:17
  • 1
    Had some trouble downloading and installing different fonts that support Korean and testing them out... but turned out it was as easy as the code below. sns.set(font='AppleGothic') solved the problem. Thanks. – Peter Oct 01 '19 at 13:19
  • @Peter Cool! Perhaps you may want to upvote / accept this answer then :-) – norok2 Oct 01 '19 at 13:32