helper-plot-hangul 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 c0z0c
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include requirements-dev.txt
5
+ recursive-include src/helper_plot_hangul/fonts *.ttf
@@ -0,0 +1,231 @@
1
+ Metadata-Version: 2.4
2
+ Name: helper-plot-hangul
3
+ Version: 0.5.0
4
+ Summary: Matplotlib 한글 폰트 자동 설정 라이브러리
5
+ Author-email: c0z0c <c0z0c.dev@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/c0z0c-helper/helper_plot_hangul
8
+ Project-URL: Repository, https://github.com/c0z0c-helper/helper_plot_hangul
9
+ Project-URL: Issues, https://github.com/c0z0c-helper/helper_plot_hangul/issues
10
+ Keywords: matplotlib,한글,hangul,font,korean,plot,visualization
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Scientific/Engineering :: Visualization
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: matplotlib>=3.2.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
30
+ Requires-Dist: black>=23.0.0; extra == "dev"
31
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # helper-plot-hangul
35
+
36
+ Matplotlib 한글 폰트 자동 설정 라이브러리
37
+
38
+ ## 개요
39
+
40
+ `helper-plot-hangul`은 Matplotlib에서 한글을 자동으로 표시할 수 있도록 폰트를 설정해주는 라이브러리입니다. 번거로운 폰트 설정 없이 간단하게 한글 그래프를 그릴 수 있습니다.
41
+
42
+ ## 특징
43
+
44
+ - **자동 폰트 설정**: NanumGothic 폰트를 자동으로 로드하고 설정
45
+ - **완전한 matplotlib 리셋**: 폰트 캐시를 포함한 완전한 초기화
46
+ - **스타일 호환**: matplotlib 스타일 적용 후에도 한글 폰트 자동 유지
47
+ - **Jupyter/Colab 최적화**: IPython 환경에서 완벽하게 작동
48
+ - **NumPy 2.0+ 호환**: 최신 NumPy와 호환되는 안전한 폰트 설정
49
+ - **내장 폰트**: NanumGothic 폰트 포함 (별도 설치 불필요)
50
+
51
+ ## 설치
52
+
53
+ ```bash
54
+ pip install helper-plot-hangul
55
+
56
+ # 테스트 서버
57
+ pip install --index-url https://test.pypi.org/simple/ helper-plot-hangul
58
+ ```
59
+
60
+ ## 사용법
61
+
62
+ ### 기본 사용법
63
+
64
+ ```python
65
+ from helper_plot_hangul import matplotlib_font_reset
66
+
67
+ # 한글 폰트 자동 설정 (NanumGothic 기본값)
68
+ plt = matplotlib_font_reset()
69
+
70
+ # 바로 한글 사용 가능
71
+ plt.plot([1, 2, 3], [1, 4, 9])
72
+ plt.title('한글 제목')
73
+ plt.xlabel('X축')
74
+ plt.ylabel('Y축')
75
+ plt.show()
76
+ ```
77
+
78
+ ### 사용자 정의 폰트 사용
79
+
80
+ ```python
81
+ from helper_plot_hangul import matplotlib_font_reset
82
+
83
+ # 시스템 폰트 이름으로 설정
84
+ plt = matplotlib_font_reset(font_family='맑은 고딕')
85
+
86
+ # 또는 폰트 파일 경로로 설정
87
+ plt = matplotlib_font_reset(font_path='/path/to/font.ttf')
88
+ ```
89
+
90
+ ### 추가 옵션 설정
91
+
92
+ ```python
93
+ from helper_plot_hangul import matplotlib_font_reset
94
+
95
+ # matplotlib rcParams 추가 설정
96
+ plt = matplotlib_font_reset(
97
+ font_family='NanumGothic',
98
+ axes_unicode_minus=False, # 마이너스 기호 깨짐 방지
99
+ font_size=12, # 기본 폰트 크기
100
+ )
101
+ ```
102
+
103
+ ### 스타일과 함께 사용
104
+
105
+ ```python
106
+ from helper_plot_hangul import matplotlib_font_reset
107
+
108
+ # 한글 폰트 먼저 설정
109
+ plt = matplotlib_font_reset()
110
+
111
+ # 스타일 적용 (한글 폰트 자동 유지)
112
+ plt.style.use('seaborn-v0_8-whitegrid')
113
+
114
+ plt.plot([1, 2, 3], [1, 4, 9])
115
+ plt.title('스타일 적용 + 한글')
116
+ plt.show()
117
+ ```
118
+
119
+ ### Jupyter/Colab에서 사용
120
+
121
+ ```python
122
+ from helper_plot_hangul import matplotlib_font_reset
123
+
124
+ # 최초 1회만 실행
125
+ matplotlib_font_reset()
126
+
127
+ # 이후 셀에서 plt 바로 사용 가능
128
+ import matplotlib.pyplot as plt
129
+
130
+ plt.plot([1, 2, 3], [1, 4, 9])
131
+ plt.title('주피터에서 한글')
132
+ plt.show()
133
+ ```
134
+
135
+ ### 선호 폰트만 등록 (리셋 없이)
136
+
137
+ ```python
138
+ from helper_plot_hangul import matplotlib_font_set
139
+
140
+ # matplotlib 리셋 없이 폰트만 변경
141
+ matplotlib_font_set(font_family='맑은 고딕', font_size=11)
142
+ ```
143
+
144
+ ## API 레퍼런스
145
+
146
+ ### `matplotlib_font_reset(font_family=None, font_path=None, **kwargs)`
147
+
148
+ matplotlib를 완전히 리셋하고 한글 폰트를 설정합니다.
149
+
150
+ **Parameters:**
151
+ - `font_family` (str, optional): 사용할 폰트 패밀리 이름 (기본값: 'NanumGothic')
152
+ - `font_path` (str, optional): 폰트 파일 경로. 지정 시 파일에서 폰트 이름 추출
153
+ - `**kwargs`: matplotlib rcParams에 전달할 추가 설정
154
+ - `axes_unicode_minus` (bool): 마이너스 기호 깨짐 방지 (기본값: False)
155
+ - `font_size` (int): 기본 폰트 크기 (기본값: 10)
156
+
157
+ **Returns:**
158
+ - `matplotlib.pyplot`: 리셋되고 한글 폰트가 설정된 pyplot 모듈
159
+
160
+ **폰트 설정 우선순위:**
161
+ 1. `font_path`가 있으면 파일에서 폰트 패밀리 이름 추출
162
+ 2. `font_family`만 있으면 해당 이름 사용
163
+ 3. 둘 다 없으면 'NanumGothic' 기본값 사용 + 자동 탐색
164
+
165
+ ### `matplotlib_font_set(font_family=None, font_path=None, **kwargs)`
166
+
167
+ matplotlib를 리셋하지 않고 선호 폰트만 등록하고 즉시 적용합니다.
168
+
169
+ **Parameters:**
170
+ - `font_family` (str, optional): 사용할 폰트 패밀리 이름
171
+ - `font_path` (str, optional): 폰트 파일 경로
172
+ - `**kwargs`: matplotlib rcParams에 전달할 추가 설정
173
+
174
+ ## 작동 원리
175
+
176
+ 1. **폰트 자동 탐색**: 패키지에 내장된 NanumGothic 폰트를 자동으로 찾아 로드
177
+ 2. **완전한 리셋**: matplotlib 모듈을 완전히 리로드하여 폰트 캐시 클리어
178
+ 3. **스타일 패치**: `matplotlib.style.use` 함수를 패치하여 스타일 적용 후 자동으로 한글 폰트 재설정
179
+ 4. **전역 등록**: IPython 환경과 호출자 네임스페이스에 plt를 자동 등록
180
+
181
+ ## 문제 해결
182
+
183
+ ### 한글이 여전히 깨져 보이는 경우
184
+
185
+ ```python
186
+ # 1. 완전 리셋 시도
187
+ from helper_plot_hangul import matplotlib_font_reset
188
+ plt = matplotlib_font_reset()
189
+
190
+ # 2. 폰트 캐시 수동 삭제 (필요시)
191
+ import matplotlib.font_manager as fm
192
+ fm._get_fontconfig_fonts.cache_clear()
193
+ ```
194
+
195
+ ### 특정 폰트 사용하고 싶은 경우
196
+
197
+ ```python
198
+ # 시스템에 설치된 폰트 사용
199
+ plt = matplotlib_font_reset(font_family='D2Coding')
200
+
201
+ # 폰트 파일 직접 지정
202
+ plt = matplotlib_font_reset(font_path='/usr/share/fonts/custom.ttf')
203
+ ```
204
+
205
+ ## 요구사항
206
+
207
+ - Python >= 3.8
208
+ - matplotlib >= 3.2.0
209
+
210
+ ## 라이센스
211
+
212
+ MIT License
213
+
214
+ ## 기여
215
+
216
+ 버그 리포트나 기능 제안은 [GitHub Issues](https://github.com/c0z0c/helper_plot_hangul/issues)에 등록해주세요.
217
+
218
+ ## 변경 이력
219
+
220
+ ### v0.5.0(2025-12-05)
221
+ - 최초 릴리스
222
+ - NanumGothic 폰트 내장
223
+ - matplotlib 완전 리셋 기능
224
+ - 스타일 호환성 자동 패치
225
+ - Jupyter/Colab 최적화
226
+
227
+ ---
228
+
229
+ jupyter_hangul를 참고하여 만들어졌습니다.
230
+ - https://c0z0c.github.io/jupyter_hangul/
231
+
@@ -0,0 +1,198 @@
1
+ # helper-plot-hangul
2
+
3
+ Matplotlib 한글 폰트 자동 설정 라이브러리
4
+
5
+ ## 개요
6
+
7
+ `helper-plot-hangul`은 Matplotlib에서 한글을 자동으로 표시할 수 있도록 폰트를 설정해주는 라이브러리입니다. 번거로운 폰트 설정 없이 간단하게 한글 그래프를 그릴 수 있습니다.
8
+
9
+ ## 특징
10
+
11
+ - **자동 폰트 설정**: NanumGothic 폰트를 자동으로 로드하고 설정
12
+ - **완전한 matplotlib 리셋**: 폰트 캐시를 포함한 완전한 초기화
13
+ - **스타일 호환**: matplotlib 스타일 적용 후에도 한글 폰트 자동 유지
14
+ - **Jupyter/Colab 최적화**: IPython 환경에서 완벽하게 작동
15
+ - **NumPy 2.0+ 호환**: 최신 NumPy와 호환되는 안전한 폰트 설정
16
+ - **내장 폰트**: NanumGothic 폰트 포함 (별도 설치 불필요)
17
+
18
+ ## 설치
19
+
20
+ ```bash
21
+ pip install helper-plot-hangul
22
+
23
+ # 테스트 서버
24
+ pip install --index-url https://test.pypi.org/simple/ helper-plot-hangul
25
+ ```
26
+
27
+ ## 사용법
28
+
29
+ ### 기본 사용법
30
+
31
+ ```python
32
+ from helper_plot_hangul import matplotlib_font_reset
33
+
34
+ # 한글 폰트 자동 설정 (NanumGothic 기본값)
35
+ plt = matplotlib_font_reset()
36
+
37
+ # 바로 한글 사용 가능
38
+ plt.plot([1, 2, 3], [1, 4, 9])
39
+ plt.title('한글 제목')
40
+ plt.xlabel('X축')
41
+ plt.ylabel('Y축')
42
+ plt.show()
43
+ ```
44
+
45
+ ### 사용자 정의 폰트 사용
46
+
47
+ ```python
48
+ from helper_plot_hangul import matplotlib_font_reset
49
+
50
+ # 시스템 폰트 이름으로 설정
51
+ plt = matplotlib_font_reset(font_family='맑은 고딕')
52
+
53
+ # 또는 폰트 파일 경로로 설정
54
+ plt = matplotlib_font_reset(font_path='/path/to/font.ttf')
55
+ ```
56
+
57
+ ### 추가 옵션 설정
58
+
59
+ ```python
60
+ from helper_plot_hangul import matplotlib_font_reset
61
+
62
+ # matplotlib rcParams 추가 설정
63
+ plt = matplotlib_font_reset(
64
+ font_family='NanumGothic',
65
+ axes_unicode_minus=False, # 마이너스 기호 깨짐 방지
66
+ font_size=12, # 기본 폰트 크기
67
+ )
68
+ ```
69
+
70
+ ### 스타일과 함께 사용
71
+
72
+ ```python
73
+ from helper_plot_hangul import matplotlib_font_reset
74
+
75
+ # 한글 폰트 먼저 설정
76
+ plt = matplotlib_font_reset()
77
+
78
+ # 스타일 적용 (한글 폰트 자동 유지)
79
+ plt.style.use('seaborn-v0_8-whitegrid')
80
+
81
+ plt.plot([1, 2, 3], [1, 4, 9])
82
+ plt.title('스타일 적용 + 한글')
83
+ plt.show()
84
+ ```
85
+
86
+ ### Jupyter/Colab에서 사용
87
+
88
+ ```python
89
+ from helper_plot_hangul import matplotlib_font_reset
90
+
91
+ # 최초 1회만 실행
92
+ matplotlib_font_reset()
93
+
94
+ # 이후 셀에서 plt 바로 사용 가능
95
+ import matplotlib.pyplot as plt
96
+
97
+ plt.plot([1, 2, 3], [1, 4, 9])
98
+ plt.title('주피터에서 한글')
99
+ plt.show()
100
+ ```
101
+
102
+ ### 선호 폰트만 등록 (리셋 없이)
103
+
104
+ ```python
105
+ from helper_plot_hangul import matplotlib_font_set
106
+
107
+ # matplotlib 리셋 없이 폰트만 변경
108
+ matplotlib_font_set(font_family='맑은 고딕', font_size=11)
109
+ ```
110
+
111
+ ## API 레퍼런스
112
+
113
+ ### `matplotlib_font_reset(font_family=None, font_path=None, **kwargs)`
114
+
115
+ matplotlib를 완전히 리셋하고 한글 폰트를 설정합니다.
116
+
117
+ **Parameters:**
118
+ - `font_family` (str, optional): 사용할 폰트 패밀리 이름 (기본값: 'NanumGothic')
119
+ - `font_path` (str, optional): 폰트 파일 경로. 지정 시 파일에서 폰트 이름 추출
120
+ - `**kwargs`: matplotlib rcParams에 전달할 추가 설정
121
+ - `axes_unicode_minus` (bool): 마이너스 기호 깨짐 방지 (기본값: False)
122
+ - `font_size` (int): 기본 폰트 크기 (기본값: 10)
123
+
124
+ **Returns:**
125
+ - `matplotlib.pyplot`: 리셋되고 한글 폰트가 설정된 pyplot 모듈
126
+
127
+ **폰트 설정 우선순위:**
128
+ 1. `font_path`가 있으면 파일에서 폰트 패밀리 이름 추출
129
+ 2. `font_family`만 있으면 해당 이름 사용
130
+ 3. 둘 다 없으면 'NanumGothic' 기본값 사용 + 자동 탐색
131
+
132
+ ### `matplotlib_font_set(font_family=None, font_path=None, **kwargs)`
133
+
134
+ matplotlib를 리셋하지 않고 선호 폰트만 등록하고 즉시 적용합니다.
135
+
136
+ **Parameters:**
137
+ - `font_family` (str, optional): 사용할 폰트 패밀리 이름
138
+ - `font_path` (str, optional): 폰트 파일 경로
139
+ - `**kwargs`: matplotlib rcParams에 전달할 추가 설정
140
+
141
+ ## 작동 원리
142
+
143
+ 1. **폰트 자동 탐색**: 패키지에 내장된 NanumGothic 폰트를 자동으로 찾아 로드
144
+ 2. **완전한 리셋**: matplotlib 모듈을 완전히 리로드하여 폰트 캐시 클리어
145
+ 3. **스타일 패치**: `matplotlib.style.use` 함수를 패치하여 스타일 적용 후 자동으로 한글 폰트 재설정
146
+ 4. **전역 등록**: IPython 환경과 호출자 네임스페이스에 plt를 자동 등록
147
+
148
+ ## 문제 해결
149
+
150
+ ### 한글이 여전히 깨져 보이는 경우
151
+
152
+ ```python
153
+ # 1. 완전 리셋 시도
154
+ from helper_plot_hangul import matplotlib_font_reset
155
+ plt = matplotlib_font_reset()
156
+
157
+ # 2. 폰트 캐시 수동 삭제 (필요시)
158
+ import matplotlib.font_manager as fm
159
+ fm._get_fontconfig_fonts.cache_clear()
160
+ ```
161
+
162
+ ### 특정 폰트 사용하고 싶은 경우
163
+
164
+ ```python
165
+ # 시스템에 설치된 폰트 사용
166
+ plt = matplotlib_font_reset(font_family='D2Coding')
167
+
168
+ # 폰트 파일 직접 지정
169
+ plt = matplotlib_font_reset(font_path='/usr/share/fonts/custom.ttf')
170
+ ```
171
+
172
+ ## 요구사항
173
+
174
+ - Python >= 3.8
175
+ - matplotlib >= 3.2.0
176
+
177
+ ## 라이센스
178
+
179
+ MIT License
180
+
181
+ ## 기여
182
+
183
+ 버그 리포트나 기능 제안은 [GitHub Issues](https://github.com/c0z0c/helper_plot_hangul/issues)에 등록해주세요.
184
+
185
+ ## 변경 이력
186
+
187
+ ### v0.5.0(2025-12-05)
188
+ - 최초 릴리스
189
+ - NanumGothic 폰트 내장
190
+ - matplotlib 완전 리셋 기능
191
+ - 스타일 호환성 자동 패치
192
+ - Jupyter/Colab 최적화
193
+
194
+ ---
195
+
196
+ jupyter_hangul를 참고하여 만들어졌습니다.
197
+ - https://c0z0c.github.io/jupyter_hangul/
198
+
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "helper-plot-hangul"
7
+ version = "0.5.0"
8
+ description = "Matplotlib 한글 폰트 자동 설정 라이브러리"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ authors = [
13
+ {name = "c0z0c", email = "c0z0c.dev@gmail.com"}
14
+ ]
15
+ keywords = ["matplotlib", "한글", "hangul", "font", "korean", "plot", "visualization"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "Intended Audience :: Science/Research",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.8",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Topic :: Scientific/Engineering :: Visualization",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+ ]
30
+
31
+ dependencies = [
32
+ "matplotlib>=3.2.0",
33
+ ]
34
+
35
+ [project.optional-dependencies]
36
+ dev = [
37
+ "pytest>=7.0.0",
38
+ "pytest-cov>=4.0.0",
39
+ "black>=23.0.0",
40
+ "ruff>=0.1.0",
41
+ ]
42
+
43
+ [project.urls]
44
+ Homepage = "https://github.com/c0z0c-helper/helper_plot_hangul"
45
+ Repository = "https://github.com/c0z0c-helper/helper_plot_hangul"
46
+ Issues = "https://github.com/c0z0c-helper/helper_plot_hangul/issues"
47
+
48
+ [tool.setuptools]
49
+ package-dir = {"" = "src"}
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["src"]
53
+
54
+ [tool.setuptools.package-data]
55
+ helper_plot_hangul = ["fonts/*.ttf"]
56
+
57
+ [tool.black]
58
+ line-length = 100
59
+ target-version = ["py38", "py39", "py310", "py311", "py312"]
60
+
61
+ [tool.ruff]
62
+ line-length = 100
63
+ target-version = "py38"
@@ -0,0 +1,4 @@
1
+ pytest>=7.0.0
2
+ pytest-cov>=4.0.0
3
+ black>=23.0.0
4
+ ruff>=0.1.0
@@ -0,0 +1 @@
1
+ matplotlib>=3.2.0
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,30 @@
1
+ """
2
+ helper-plot-hangul
3
+ ==================
4
+
5
+ Matplotlib 한글 폰트 자동 설정 라이브러리
6
+
7
+ 주요 기능:
8
+ - 자동 폰트 설정: NanumGothic 폰트를 자동으로 로드하고 설정
9
+ - 완전한 matplotlib 리셋: 폰트 캐시를 포함한 완전한 초기화
10
+ - 스타일 호환: matplotlib 스타일 적용 후에도 한글 폰트 자동 유지
11
+ - Jupyter/Colab 최적화: IPython 환경에서 완벽하게 작동
12
+
13
+ 기본 사용법:
14
+ from helper_plot_hangul import matplotlib_font_reset
15
+
16
+ plt = matplotlib_font_reset()
17
+ plt.plot([1, 2, 3], [1, 4, 9])
18
+ plt.title('한글 제목')
19
+ plt.show()
20
+ """
21
+
22
+ __version__ = "0.5.0"
23
+
24
+ from .helper_plot_hangul import matplotlib_font_reset, matplotlib_font_set
25
+
26
+ __all__ = [
27
+ "matplotlib_font_reset",
28
+ "matplotlib_font_set",
29
+ "__version__",
30
+ ]
@@ -0,0 +1,250 @@
1
+ import os
2
+ import sys
3
+ import matplotlib.pyplot as plt
4
+ import matplotlib.font_manager as fm
5
+ import importlib.resources as resources
6
+ import inspect
7
+ import warnings
8
+ from pathlib import Path
9
+ from typing import Any
10
+ import logging
11
+ try:
12
+ import IPython
13
+ from IPython.display import HTML
14
+ IPYTHON_AVAILABLE = True
15
+ except ImportError:
16
+ IPYTHON_AVAILABLE = False
17
+
18
+ logger = logging.getLogger(__name__)
19
+ logger.setLevel(logging.INFO)
20
+ if not logger.handlers:
21
+ sh = logging.StreamHandler()
22
+ sh.setLevel(logger.level)
23
+ sh.setFormatter(logging.Formatter("%(asctime)s %(levelname)s [%(name)s] %(message)s"))
24
+ logger.addHandler(sh)
25
+
26
+ def matplotlib_font_reset(font_family: str | None = None, font_path: str | None = None, **kwargs: Any) -> Any:
27
+ """matplotlib 완전 리셋 (NumPy 호환성 개선).
28
+
29
+ matplotlib 모듈을 완전히 리로드하고 한글 폰트를 설정합니다.
30
+ NumPy 2.0+ 호환성을 고려한 안전한 폰트 설정을 수행합니다.
31
+
32
+ Parameters
33
+ ----------
34
+ font_family : str, optional
35
+ 사용할 폰트 패밀리 이름 (기본값: 'NanumGothic')
36
+ font_path : str, optional
37
+ 폰트 파일 경로. 지정 시 파일에서 폰트 이름 추출 (우선순위 최상위)
38
+ **kwargs
39
+ matplotlib rcParams에 전달할 추가 설정 (기본값: axes.unicode_minus=False, font.size=10)
40
+
41
+ Returns
42
+ -------
43
+ matplotlib.pyplot
44
+ 리셋되고 한글 폰트가 설정된 pyplot 모듈.
45
+
46
+ Notes
47
+ -----
48
+ 폰트 설정 우선순위:
49
+ 1. font_path가 있으면 파일에서 폰트 패밀리 이름 추출
50
+ 2. font_family만 있으면 해당 이름 사용
51
+ 3. 둘 다 없으면 'NanumGothic' 기본값 사용 + 자동 탐색
52
+ """
53
+
54
+ if isinstance(font_family, (str, bytes, os.PathLike)) and font_family and os.path.exists(font_family):
55
+ font_path = str(font_family)
56
+ font_family = None
57
+
58
+ # 기본값 설정
59
+ default_kwargs = {'axes.unicode_minus': False, 'font.size': 10}
60
+ default_kwargs.update(kwargs)
61
+
62
+ modules_to_remove = [mod for mod in sys.modules if mod.startswith('matplotlib')]
63
+ for mod in modules_to_remove:
64
+ del sys.modules[mod]
65
+
66
+ # matplotlib 재임포트
67
+ import matplotlib.pyplot as plt
68
+ import matplotlib.font_manager as fm
69
+
70
+ # 폰트 캐시 클리어 (중요!)
71
+ try:
72
+ fm._get_fontconfig_fonts.cache_clear()
73
+ except:
74
+ pass
75
+
76
+ try:
77
+ fm.fontManager.__init__()
78
+ except:
79
+ pass
80
+
81
+ # font_path가 없고 font_family도 없으면 자동 탐색
82
+ if font_path is None and font_family is None:
83
+ font_family = 'NanumGothic'
84
+ # 1. 개발 환경: 로컬 fonts 폴더 확인
85
+ local_font_path = Path(__file__).parent / "fonts" / "NanumGothic.ttf"
86
+
87
+ if local_font_path.exists():
88
+ font_path = str(local_font_path)
89
+ else:
90
+ # 2. pip 배포 환경: 패키지 내부 fonts 폴더
91
+ try:
92
+ font_path = str(resources.files("helper_plot_hangul").joinpath("fonts/NanumGothic.ttf"))
93
+ except Exception:
94
+ font_path = None
95
+ logger.debug(f"자동 탐색된 폰트 경로: {font_path}")
96
+
97
+ # 우선순위: font_path > font_family
98
+ if font_path:
99
+ try:
100
+ fm.fontManager.addfont(font_path) # matplotlib >= 3.2
101
+ fp = fm.FontProperties(fname=font_path)
102
+ font_name = fp.get_name()
103
+ plt.rcParams['font.family'] = font_name
104
+ except Exception:
105
+ # 실패 시 font_family 사용
106
+ if font_family:
107
+ plt.rcParams['font.family'] = font_family
108
+ else:
109
+ plt.rcParams['font.family'] = 'NanumGothic'
110
+ elif font_family:
111
+ plt.rcParams['font.family'] = font_family
112
+ else:
113
+ plt.rcParams['font.family'] = 'NanumGothic'
114
+ logger.debug(f"설정된 폰트 패밀리: {plt.rcParams['font.family']}")
115
+
116
+ # 추가 설정 적용
117
+ for key, value in default_kwargs.items():
118
+ plt.rcParams[key] = value
119
+
120
+ # IPython 환경에서 전역 등록 (Jupyter/Colab 호환성 개선)
121
+ try:
122
+ # IPython/Jupyter 사용자 네임스페이스에 등록
123
+ if IPYTHON_AVAILABLE:
124
+ ipy = IPython.get_ipython()
125
+ if ipy is not None:
126
+ ipy.user_ns["plt"] = plt
127
+
128
+ # 호출자 모듈의 전역(namespace)에 plt를 넣어 할당 없이 사용 가능하도록 함
129
+ try:
130
+ caller = inspect.currentframe().f_back
131
+ if caller is not None:
132
+ caller.f_globals["plt"] = plt
133
+ except Exception:
134
+ pass
135
+
136
+ # 현재 모듈의 globals에도 보장
137
+ globals()["plt"] = plt
138
+ except Exception:
139
+ globals()["plt"] = plt
140
+
141
+ # 선호 폰트 정보 저장 (스타일 적용 후 재적용용)
142
+ globals()["_preferred_font_path"] = font_path
143
+ globals()["_preferred_font_family"] = font_family if font_family else plt.rcParams.get('font.family')
144
+ globals()["_preferred_font_kwargs"] = default_kwargs
145
+
146
+ # matplotlib.style.use 패치 (최초 1회만)
147
+ if not globals().get("_style_patched", False):
148
+ _patch_style_use()
149
+ globals()["_style_patched"] = True
150
+
151
+ return plt
152
+
153
+
154
+ def _reapply_font_rcparams():
155
+ """모듈에 저장된 선호 폰트를 rcParams에 재적용 (스타일 적용 후 자동 호출)."""
156
+ try:
157
+ import matplotlib.font_manager as fm
158
+ import matplotlib.pyplot as _plt
159
+
160
+ font_path = globals().get("_preferred_font_path")
161
+ font_family = globals().get("_preferred_font_family")
162
+ kwargs = globals().get("_preferred_font_kwargs", {})
163
+
164
+ if font_path:
165
+ try:
166
+ fm.fontManager.addfont(font_path)
167
+ fp = fm.FontProperties(fname=font_path)
168
+ font_name = fp.get_name()
169
+ _plt.rcParams['font.family'] = font_name
170
+ logger.debug(f"폰트 재적용: {font_name} (경로: {font_path})")
171
+ except Exception as e:
172
+ logger.debug(f"폰트 경로 재적용 실패: {e}")
173
+ if font_family:
174
+ _plt.rcParams['font.family'] = font_family
175
+ elif font_family:
176
+ _plt.rcParams['font.family'] = font_family
177
+ logger.debug(f"폰트 재적용: {font_family}")
178
+
179
+ # 기타 저장된 rc 설정 재적용
180
+ for k, v in kwargs.items():
181
+ _plt.rcParams[k] = v
182
+
183
+ except Exception as e:
184
+ logger.debug(f"폰트 재적용 중 예외 발생: {e}")
185
+
186
+
187
+ def _patch_style_use():
188
+ """matplotlib.style.use를 패치하여 스타일 적용 후 자동으로 한글 폰트 재설정."""
189
+ try:
190
+ import matplotlib.style as mstyle
191
+ _orig_style_use = mstyle.use
192
+
193
+ def _patched_style_use(style, *args, **kwargs):
194
+ result = _orig_style_use(style, *args, **kwargs)
195
+ # 스타일 적용 직후 저장된 한글 폰트 재적용
196
+ if globals().get("_preferred_font_path") or globals().get("_preferred_font_family"):
197
+ _reapply_font_rcparams()
198
+ logger.debug(f"스타일 '{style}' 적용 후 한글 폰트 자동 재설정 완료")
199
+ return result
200
+
201
+ mstyle.use = _patched_style_use
202
+ logger.debug("matplotlib.style.use 패치 완료")
203
+
204
+ except Exception as e:
205
+ logger.debug(f"matplotlib.style.use 패치 실패 (무시): {e}")
206
+
207
+
208
+ def matplotlib_font_set(font_family: str | None = None, font_path: str | None = None, **kwargs: Any):
209
+ """matplotlib_font_reset를 호출하지 않고 선호 폰트만 등록 (즉시 적용).
210
+
211
+ Parameters
212
+ ----------
213
+ font_family : str, optional
214
+ 사용할 폰트 패밀리 이름
215
+ font_path : str, optional
216
+ 폰트 파일 경로
217
+ **kwargs
218
+ matplotlib rcParams에 전달할 추가 설정
219
+ """
220
+ import matplotlib.pyplot as _plt
221
+
222
+ default_kwargs = {'axes.unicode_minus': False, 'font.size': 10}
223
+ default_kwargs.update(kwargs)
224
+
225
+ globals()["_preferred_font_path"] = font_path
226
+ globals()["_preferred_font_family"] = font_family
227
+ globals()["_preferred_font_kwargs"] = default_kwargs
228
+
229
+ # 현재 세션의 rcParams에도 즉시 적용
230
+ _reapply_font_rcparams()
231
+
232
+ # 패치 적용
233
+ if not globals().get("_style_patched", False):
234
+ _patch_style_use()
235
+ globals()["_style_patched"] = True
236
+
237
+
238
+ matplotlib_font_reset()
239
+
240
+ # 예시 사용법
241
+ if __name__ == "__main__":
242
+ # plt = matplotlib_font_reset(r'src\helper_plot_hangul\fonts\NanumGothic.ttf')
243
+
244
+ # 스타일 적용 테스트 (자동으로 한글 폰트 재설정됨)
245
+ plt.style.use('seaborn-v0_8-whitegrid')
246
+ plt.plot([1, 2, 3], [1, 4, 9])
247
+ plt.title('한글 폰트 테스트')
248
+ plt.xlabel('X축')
249
+ plt.ylabel('Y축')
250
+ plt.show()
@@ -0,0 +1,231 @@
1
+ Metadata-Version: 2.4
2
+ Name: helper-plot-hangul
3
+ Version: 0.5.0
4
+ Summary: Matplotlib 한글 폰트 자동 설정 라이브러리
5
+ Author-email: c0z0c <c0z0c.dev@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/c0z0c-helper/helper_plot_hangul
8
+ Project-URL: Repository, https://github.com/c0z0c-helper/helper_plot_hangul
9
+ Project-URL: Issues, https://github.com/c0z0c-helper/helper_plot_hangul/issues
10
+ Keywords: matplotlib,한글,hangul,font,korean,plot,visualization
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Scientific/Engineering :: Visualization
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: matplotlib>=3.2.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
30
+ Requires-Dist: black>=23.0.0; extra == "dev"
31
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # helper-plot-hangul
35
+
36
+ Matplotlib 한글 폰트 자동 설정 라이브러리
37
+
38
+ ## 개요
39
+
40
+ `helper-plot-hangul`은 Matplotlib에서 한글을 자동으로 표시할 수 있도록 폰트를 설정해주는 라이브러리입니다. 번거로운 폰트 설정 없이 간단하게 한글 그래프를 그릴 수 있습니다.
41
+
42
+ ## 특징
43
+
44
+ - **자동 폰트 설정**: NanumGothic 폰트를 자동으로 로드하고 설정
45
+ - **완전한 matplotlib 리셋**: 폰트 캐시를 포함한 완전한 초기화
46
+ - **스타일 호환**: matplotlib 스타일 적용 후에도 한글 폰트 자동 유지
47
+ - **Jupyter/Colab 최적화**: IPython 환경에서 완벽하게 작동
48
+ - **NumPy 2.0+ 호환**: 최신 NumPy와 호환되는 안전한 폰트 설정
49
+ - **내장 폰트**: NanumGothic 폰트 포함 (별도 설치 불필요)
50
+
51
+ ## 설치
52
+
53
+ ```bash
54
+ pip install helper-plot-hangul
55
+
56
+ # 테스트 서버
57
+ pip install --index-url https://test.pypi.org/simple/ helper-plot-hangul
58
+ ```
59
+
60
+ ## 사용법
61
+
62
+ ### 기본 사용법
63
+
64
+ ```python
65
+ from helper_plot_hangul import matplotlib_font_reset
66
+
67
+ # 한글 폰트 자동 설정 (NanumGothic 기본값)
68
+ plt = matplotlib_font_reset()
69
+
70
+ # 바로 한글 사용 가능
71
+ plt.plot([1, 2, 3], [1, 4, 9])
72
+ plt.title('한글 제목')
73
+ plt.xlabel('X축')
74
+ plt.ylabel('Y축')
75
+ plt.show()
76
+ ```
77
+
78
+ ### 사용자 정의 폰트 사용
79
+
80
+ ```python
81
+ from helper_plot_hangul import matplotlib_font_reset
82
+
83
+ # 시스템 폰트 이름으로 설정
84
+ plt = matplotlib_font_reset(font_family='맑은 고딕')
85
+
86
+ # 또는 폰트 파일 경로로 설정
87
+ plt = matplotlib_font_reset(font_path='/path/to/font.ttf')
88
+ ```
89
+
90
+ ### 추가 옵션 설정
91
+
92
+ ```python
93
+ from helper_plot_hangul import matplotlib_font_reset
94
+
95
+ # matplotlib rcParams 추가 설정
96
+ plt = matplotlib_font_reset(
97
+ font_family='NanumGothic',
98
+ axes_unicode_minus=False, # 마이너스 기호 깨짐 방지
99
+ font_size=12, # 기본 폰트 크기
100
+ )
101
+ ```
102
+
103
+ ### 스타일과 함께 사용
104
+
105
+ ```python
106
+ from helper_plot_hangul import matplotlib_font_reset
107
+
108
+ # 한글 폰트 먼저 설정
109
+ plt = matplotlib_font_reset()
110
+
111
+ # 스타일 적용 (한글 폰트 자동 유지)
112
+ plt.style.use('seaborn-v0_8-whitegrid')
113
+
114
+ plt.plot([1, 2, 3], [1, 4, 9])
115
+ plt.title('스타일 적용 + 한글')
116
+ plt.show()
117
+ ```
118
+
119
+ ### Jupyter/Colab에서 사용
120
+
121
+ ```python
122
+ from helper_plot_hangul import matplotlib_font_reset
123
+
124
+ # 최초 1회만 실행
125
+ matplotlib_font_reset()
126
+
127
+ # 이후 셀에서 plt 바로 사용 가능
128
+ import matplotlib.pyplot as plt
129
+
130
+ plt.plot([1, 2, 3], [1, 4, 9])
131
+ plt.title('주피터에서 한글')
132
+ plt.show()
133
+ ```
134
+
135
+ ### 선호 폰트만 등록 (리셋 없이)
136
+
137
+ ```python
138
+ from helper_plot_hangul import matplotlib_font_set
139
+
140
+ # matplotlib 리셋 없이 폰트만 변경
141
+ matplotlib_font_set(font_family='맑은 고딕', font_size=11)
142
+ ```
143
+
144
+ ## API 레퍼런스
145
+
146
+ ### `matplotlib_font_reset(font_family=None, font_path=None, **kwargs)`
147
+
148
+ matplotlib를 완전히 리셋하고 한글 폰트를 설정합니다.
149
+
150
+ **Parameters:**
151
+ - `font_family` (str, optional): 사용할 폰트 패밀리 이름 (기본값: 'NanumGothic')
152
+ - `font_path` (str, optional): 폰트 파일 경로. 지정 시 파일에서 폰트 이름 추출
153
+ - `**kwargs`: matplotlib rcParams에 전달할 추가 설정
154
+ - `axes_unicode_minus` (bool): 마이너스 기호 깨짐 방지 (기본값: False)
155
+ - `font_size` (int): 기본 폰트 크기 (기본값: 10)
156
+
157
+ **Returns:**
158
+ - `matplotlib.pyplot`: 리셋되고 한글 폰트가 설정된 pyplot 모듈
159
+
160
+ **폰트 설정 우선순위:**
161
+ 1. `font_path`가 있으면 파일에서 폰트 패밀리 이름 추출
162
+ 2. `font_family`만 있으면 해당 이름 사용
163
+ 3. 둘 다 없으면 'NanumGothic' 기본값 사용 + 자동 탐색
164
+
165
+ ### `matplotlib_font_set(font_family=None, font_path=None, **kwargs)`
166
+
167
+ matplotlib를 리셋하지 않고 선호 폰트만 등록하고 즉시 적용합니다.
168
+
169
+ **Parameters:**
170
+ - `font_family` (str, optional): 사용할 폰트 패밀리 이름
171
+ - `font_path` (str, optional): 폰트 파일 경로
172
+ - `**kwargs`: matplotlib rcParams에 전달할 추가 설정
173
+
174
+ ## 작동 원리
175
+
176
+ 1. **폰트 자동 탐색**: 패키지에 내장된 NanumGothic 폰트를 자동으로 찾아 로드
177
+ 2. **완전한 리셋**: matplotlib 모듈을 완전히 리로드하여 폰트 캐시 클리어
178
+ 3. **스타일 패치**: `matplotlib.style.use` 함수를 패치하여 스타일 적용 후 자동으로 한글 폰트 재설정
179
+ 4. **전역 등록**: IPython 환경과 호출자 네임스페이스에 plt를 자동 등록
180
+
181
+ ## 문제 해결
182
+
183
+ ### 한글이 여전히 깨져 보이는 경우
184
+
185
+ ```python
186
+ # 1. 완전 리셋 시도
187
+ from helper_plot_hangul import matplotlib_font_reset
188
+ plt = matplotlib_font_reset()
189
+
190
+ # 2. 폰트 캐시 수동 삭제 (필요시)
191
+ import matplotlib.font_manager as fm
192
+ fm._get_fontconfig_fonts.cache_clear()
193
+ ```
194
+
195
+ ### 특정 폰트 사용하고 싶은 경우
196
+
197
+ ```python
198
+ # 시스템에 설치된 폰트 사용
199
+ plt = matplotlib_font_reset(font_family='D2Coding')
200
+
201
+ # 폰트 파일 직접 지정
202
+ plt = matplotlib_font_reset(font_path='/usr/share/fonts/custom.ttf')
203
+ ```
204
+
205
+ ## 요구사항
206
+
207
+ - Python >= 3.8
208
+ - matplotlib >= 3.2.0
209
+
210
+ ## 라이센스
211
+
212
+ MIT License
213
+
214
+ ## 기여
215
+
216
+ 버그 리포트나 기능 제안은 [GitHub Issues](https://github.com/c0z0c/helper_plot_hangul/issues)에 등록해주세요.
217
+
218
+ ## 변경 이력
219
+
220
+ ### v0.5.0(2025-12-05)
221
+ - 최초 릴리스
222
+ - NanumGothic 폰트 내장
223
+ - matplotlib 완전 리셋 기능
224
+ - 스타일 호환성 자동 패치
225
+ - Jupyter/Colab 최적화
226
+
227
+ ---
228
+
229
+ jupyter_hangul를 참고하여 만들어졌습니다.
230
+ - https://c0z0c.github.io/jupyter_hangul/
231
+
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ requirements-dev.txt
6
+ requirements.txt
7
+ src/helper_plot_hangul/__init__.py
8
+ src/helper_plot_hangul/helper_plot_hangul.py
9
+ src/helper_plot_hangul.egg-info/PKG-INFO
10
+ src/helper_plot_hangul.egg-info/SOURCES.txt
11
+ src/helper_plot_hangul.egg-info/dependency_links.txt
12
+ src/helper_plot_hangul.egg-info/requires.txt
13
+ src/helper_plot_hangul.egg-info/top_level.txt
14
+ src/helper_plot_hangul/fonts/NanumGothic.ttf
@@ -0,0 +1,7 @@
1
+ matplotlib>=3.2.0
2
+
3
+ [dev]
4
+ pytest>=7.0.0
5
+ pytest-cov>=4.0.0
6
+ black>=23.0.0
7
+ ruff>=0.1.0
@@ -0,0 +1 @@
1
+ helper_plot_hangul