目的
Matplotlibで日本語を使用する場合、
デフォルト設定だと、下記のように文字化けしてしまいます。
一方、日本語設定する記事は色々とありますが、上手くいかないものが多かったので、
今回、自分自身でまとめることにしました。

概要
実施する内容は下記の3点です。
- ttffファイルのダウンロードおよび指定フォルダへの保存
- matplotlibrcファイルの書き換え
- jsonファイルの書き換え
ttfファイルダウンロード
①下記のサイトにアクセスします。
②下記の赤枠のIPAexゴシックのzipファイルをダウンロードします。

③下記のipaexg.ttffファイルを使用します。指定フォルダへの保存先は後に記述します。

matplotlibrcファイルの書き換えとttfファイルの保存先
ファイルの検索
JupyterLab
import matplotlib
print(matplotlib.matplotlib_fname())
実行結果
/Users/username/jupyter/lib/python3.10/site-packages/matplotlib/mpl-data/matplotlibrc
matplotlibrcファイル書き換えとttfファイル保存
①matplotlibrcファイルを開いて、
「#font.family」と検索し、下記のように変更を行います。
変更前
#font.family : sans-serif
変更後
font.family:IPAexGothic
②同一階層にあるfontフォルダ
→ttfフォルダに先ほどダウンロードした「ipaexg.ttf」を保存します。

jsonファイルの書き換え
ファイルの検索
JupyterLab
print(matplotlib.get_cachedir())
実行結果
/Users/username/.matplotlib
隠しファイル表示
ホームフォルダで隠しファイルを表示します。

command + shift + .(ピリオド)で隠しファイルを表示し、
.matplotlibフォルダの中にあるfontlist-v330.jsonを開きます。

ファイルの書き換え
fontlist-v330.jsonファイルを開いて、「#font.family」と検索し、変更を行います。
下記の追記内容を”ttflist”: […]内に追加します。
追記内容
{
"fname": "fonts/ttf/ipaexg.ttf",
"name": "IPAexGothic",
"style": "normal",
"variant": "normal",
"weight": "regular",
"stretch": "normal",
"size": "scalable",
"__class__": "FontEntry"
},
下記は、変更前の内容になります。
変更前
(省略)
{
"fname": "fonts/pdfcorefonts/Times-Roman.afm",
"name": "Times",
"style": "normal",
"variant": "normal",
"weight": "roman",
"stretch": "normal",
"size": "scalable",
"__class__": "FontEntry"
}
],
"ttflist": [
{
"fname": "fonts/ttf/STIXGeneralItalic.ttf",
"name": "STIXGeneral",
"style": "italic",
"variant": "normal",
"weight": 400,
"stretch": "normal",
"size": "scalable",
"__class__": "FontEntry"
},
(省略)
下記は、変更後の内容になります。
変更後
(省略)
{
"fname": "fonts/pdfcorefonts/Times-Roman.afm",
"name": "Times",
"style": "normal",
"variant": "normal",
"weight": "roman",
"stretch": "normal",
"size": "scalable",
"__class__": "FontEntry"
}
],
"ttflist": [
{
"fname": "fonts/ttf/ipaexg.ttf",
"name": "IPAexGothic",
"style": "normal",
"variant": "normal",
"weight": "regular",
"stretch": "normal",
"size": "scalable",
"__class__": "FontEntry"
},
{
"fname": "fonts/ttf/STIXGeneralItalic.ttf",
"name": "STIXGeneral",
"style": "italic",
"variant": "normal",
"weight": 400,
"stretch": "normal",
"size": "scalable",
"__class__": "FontEntry"
},
(省略)
以上で設定完了です。
注意事項

上記の設定を行った後に、実行しているファイルの再起動が必要な場合があるので、注意して下さい。
私の場合、Jupyterで実行していたファイルを停止して、Jupyterを再起動したところ、
下記のように、日本語が表示されるようになりました。