回答編集履歴
1
回答のコードでは自前の環境でうまく動かなかったので修正版ソースを追記
test
CHANGED
@@ -54,4 +54,40 @@
|
|
54
54
|
`pkg_resources`は`setuptools`が入っていなければ使えないようなのですが,
|
55
55
|
`pip`でパッケージを管理していれば,大体入っていると思うので,まぁ問題ないでしょう。
|
56
56
|
|
57
|
+
## 追記
|
58
|
+
新しいWindows環境を構築することがあり,上記回答のコードを試したところうまくいかなかったので,
|
59
|
+
自前で簡易的なバージョンチェック関数を用意する修正版を追記します。
|
57
60
|
|
61
|
+
```diff
|
62
|
+
--- japanize_matplotlib.py.old 2023-10-24 21:25:12.616377790 +0900
|
63
|
+
+++ japanize_matplotlib.py 2023-10-24 21:26:23.053102208 +0900
|
64
|
+
@@ -2,19 +2,25 @@ import os
|
65
|
+
|
66
|
+
import matplotlib
|
67
|
+
from matplotlib import font_manager
|
68
|
+
-from distutils.version import LooseVersion
|
69
|
+
+import re
|
70
|
+
|
71
|
+
FONTS_DIR = 'fonts'
|
72
|
+
FONT_NAME = "IPAexGothic"
|
73
|
+
FONT_TTF = 'ipaexg.ttf'
|
74
|
+
|
75
|
+
|
76
|
+
+def _is_support_createFontList(version):
|
77
|
+
+ # check matplotlib version < 3.2
|
78
|
+
+ pn = re.search(r'([0-9]+)\.([0-9]+)[^0-9]*', version)
|
79
|
+
+ ver_plus_subver_per_1000 = float(pn.group(1)) + float(pn.group(2)) / 1000
|
80
|
+
+ return ver_plus_subver_per_1000 < 3 + 2 / 1000
|
81
|
+
+
|
82
|
+
+
|
83
|
+
def japanize():
|
84
|
+
font_dir_path = get_font_path()
|
85
|
+
font_dirs = [font_dir_path]
|
86
|
+
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
|
87
|
+
- is_support_createFontList = LooseVersion(matplotlib.__version__) < '3.2'
|
88
|
+
- if is_support_createFontList:
|
89
|
+
+ if _is_support_createFontList(matplotlib.__version__):
|
90
|
+
font_list = font_manager.createFontList(font_files)
|
91
|
+
font_manager.fontManager.ttflist.extend(font_list)
|
92
|
+
else:
|
93
|
+
```
|