I am working with matplotlib in Jupyter, and my data includes Korean characters. Matplotlib does not support Korean character yet, so I was advised to set character on matplotlib manually. Without setting the font, my sample graph displaces square empty boxes.
Sample plot using Korean characters.
objects = ('??', '?', '?', '???', '???', '??')
y_pos = np.arange(len(objects))
performance = [10,8,6,4,2,1]
plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.ylabel('Usage')
plt.title('Programming language usage')
plt.show()
Following few examples on the internet, here's what I have done.
- Download Korean font (.ttf)
- Copy the font in my Font directory ('/Users/Library/Fonts')
- Restart Jupyter kernel and test
And I ran my matplotlib once more to see if it would turn out correctly, but I still get empty boxes.
This is the code I ran in Jupyter.
from matplotlib import font_manager, rc
font_name = font_manager.FontProperties(fname = '/Users/Library/Fonts/custom/NanumBarunGothic.ttf').get_name()
rc('font', family = font_name)
And this is the error message.
/Users/anaconda/envs/my_vir_env/lib/python3.4/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['NanumBarunGothic'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
So this is what I think I am doing wrong. I am not putting the font file in the right directory for my Jupyter, which is running on virenv on my machine. My question is where is this directory? I checked 'font_manager.py' file but I could not get much out of it. The file says that my OS font directory is indeed
User/Library/Fonts
I appreciate any help!
Thank you in advance!
See Question&Answers more detail:
os