[PYTHON] (Mac) How to display Japanese with Matplotlib and Seaborn At MacOS Sierra

0. Introduction

It doesn't matter, but this is my first post. I was doing Knock 100 language processing with Python3, and when I tried to display the graph with matplotlib, I was in agony with the Japanese display. So don't forget to make a note.

1. Conclusion

Wisdom of ancestors + *** Delete cache file ***

is.

1-1. Wisdom of ancestors

From here [Seaborn] Display Japanese (change font)

or Below is the method I tried (recommended because it is new?). I think it will definitely work here.

1-1'. Change Seaborn font settings from font introduction

If you have completed the wisdom setting of your ancestors, skip it and go to [1-2. Delete cache](http://qiita.com/kamuiroeru/items/6853f14dc493ec5063f7#1-2-Delete cache file).

(1) Font introduction

Bring a suitable font and install it.

I will use IPAex font following my predecessor. After downloading and unzipping, there should be a file called ipaexg.ttf, so let's install it as it is (double-click ipaexg.ttf in Finder).

(2) Seaborn settings

Look for rcmod.py. The ancestor python_install_folder/lib/site-package/seabornIt says that it is inside. But in my environment (because it is managed by pyenv) ~/.pyenv/versions/3.5.2/lib/python3.5/site-packages/seaborn It was in.

2016/12/25 postscript: When I reintroduced the environment with anaconda, it was in a deeper hierarchy. ~/.pyenv/versions/anaconda3-[versionNum]/lib/python3.5/site-packages/seaborn

Once you find rcmod.py, make two changes in the editor (after backing it up).

Around lines 81 and 82

def set(context="notebook", style="darkgrid", palette="deep",
        font="sans-serif", font_scale=1, color_codes=False, rc=None):

Around line 190

"font.family": ["sans-serif"],

of " san-serif " to " IPAexGothic "(new font name) Change to.

Save and complete the seaborn font settings. Japanese display is not possible yet.

(Small story) What if I use the originally installed TrueType fonts for Japanese?

You can see the installed fonts from Font Book. δΎ‹

Look at the Family item in the details view. In this case, it's Migu 1P. Specify the item name written in this family as the new font name. Example Changed " san-serif " to " Migu 1P "(new font name)

1-2. Delete cache file

Sorry I made you wait. This is the main subject. To put it simply,

fontList.py3k.cache Or *** Erase fontList.json! !! !! !! *** ***

that's all. Probably in ``` ~ / .matplotlib /` ``. It's the directory where matplotlibrc is located. If there are more than one, the one directly under the home directory should take precedence.

Let's delete it quickly.

cd ~/.matplotlib

After,

rm -f fontList.py3k.cache
rm -f fontList.json

Now let's run matplotlib. I think it will take longer than usual because the cache file will be recreated ... how is it? It went well?

** 2018/02/05 postscript ** With the recent matplotlib (version 2.1.0), FontList.py3k.cache was not found and was reflected by deleting fontList.json.


Why you have to delete the cache

(Since it is my own reasoning, it may contain mistakes etc.)

It seems that matplotlib makes a cache file of what font file exists at the first startup and then reads it.

Source matplotlib official GitHub issue Won't use a font although it can be found by the FontManager #3590

you'll need to remove the fontList.cache file everytime you want matplotlib to discover new fonts.

Because there is a reply

It seems that every time you change the font settings ** you have to change the cache file **.

Recommended Posts

(Mac) How to display Japanese with Matplotlib and Seaborn At MacOS Sierra
How to display python Japanese with lolipop
How to display images continuously with matplotlib Note
Japanese display of matplotlib, seaborn
How to run Jupyter and Spark on Mac with minimal settings
Japanese settings for matplotlib and Seaborn axes
How to title multiple figures with matplotlib
How to suppress display error in matplotlib
How to use Japanese with NLTK plot
Display Japanese graphs with VS Code + matplotlib
How to enter Japanese with Python curses
How to install cx_Oracle on macOS Sierra
[Python] How to specify the window display position and size of matplotlib
How to get started with the 2020 Python project (windows wsl and mac standardization)
How to turn off the scale value display while leaving the grid with matplotlib
I want to display multiple images with matplotlib.
[Python] How to draw multiple graphs with Matplotlib
Wrap and display Japanese sentences well with pyglet
How to switch between Linux and Mac shells
Japanese with matplotlib
[Python] How to handle Japanese characters with openCV
How to make Linux compatible with Japanese keyboard
[Linux] How to display CPU usage, display header, and not display grep process with ps command
[Python] How to draw a line graph with Matplotlib
How to share folders with Docker and Windows with tensorflow
It's too troublesome to display Japanese with Vim's python3.
How to extract null values and non-null values with pandas
How to loop and play gif video with openCV
[Python] How to create a 2D histogram with Matplotlib
[How to!] Learn and play Super Mario with Tensorflow !!
[Python] How to draw a scatter plot with Matplotlib
How to use Matplotlib
[Super easy! ] How to display the contents of dictionaries and lists including Japanese in Python
How to display hover text and text that can be executed by clicking with Minecraft plugin
[Graph drawing] I tried to write a bar graph of multiple series with matplotlib and seaborn
How to insert a specific process at the start and end of spider with scrapy
[Python] Read the csv file and display the figure with matplotlib
[Python] How to play with class variables with decorator and metaclass
[Ev3dev] How to display bmp image on LCD with python
How to add new data (lines and plots) using matplotlib
How to do Bulk Update with PyMySQL and notes [Python]
How to display a list of installable versions with pyenv
How to scrape at speed per second with Python Selenium
How to create dataframes and mess with elements in pandas
How to install Theano on Mac OS X with homebrew
How to log in to AtCoder with Python and submit automatically
How to display the CPU usage, pod name, and IP address of a pod created with Kubernetes
I was surprised at how to save objects with python, which is lean and very energy-saving.
How to quickly create a machine learning environment using Jupyter Notebook on macOS Sierra with anaconda
[Seaborn] Display Japanese (change font)
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
How to Delete with SQLAlchemy?
How to set a shortcut to switch full-width and half-width with IBus
How to not escape Japanese when dealing with json in python
How to import CSV and TSV files into SQLite with Python
How to deal with errors when installing whitenoise and deploying to Heroku
Linking Python and Arduino to display IME On / Off with LED