Last active
March 11, 2024 01:27
-
-
Save rhee-elten/d36d1e907e66a9a548fdbfdceb2c469a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mpl_korfont.py | |
# coding: utf-8 | |
import sys | |
from os.path import isfile, basename | |
""" | |
font size comparison (kB): | |
1300 NanumBarunGothicSubset.ttf | |
1328 d2coding-subset.ttf | |
1368 d2coding-ligature-subset.ttf | |
4088 d2coding-full.ttf | |
""" | |
# _FAMILY = "NanumBarunGothic" | |
# _URL = "https://cdn.jsdelivr.net/gh/moonspam/NanumBarunGothic@latest/NanumBarunGothicSubset.ttf" | |
# _FAMILY = "D2Coding" | |
# _URL = "https://cdn.jsdelivr.net/gh/wan2land/d2coding/fonts/d2coding-subset.ttf" | |
# _FAMILY = "D2Coding ligature" | |
# _URL = "https://cdn.jsdelivr.net/gh/wan2land/d2coding/fonts/d2coding-ligature-subset.ttf" | |
_FAMILY = "D2Coding" | |
_URL = "https://cdn.jsdelivr.net/gh/wan2land/d2coding/fonts/d2coding-full.ttf" | |
_FONT = basename(_URL) | |
_cmd_install_font = f"""env mkdir -p .fonts && curl -q -s -L -o .fonts/{_FONT} {_URL}""" | |
if not isfile(f".fonts/{_FONT}"): | |
try: | |
get_ipython().run_line_magic("sx", _cmd_install_font) | |
except: | |
print(sys.exc_info()[1], file=sys.stderr) | |
from subprocess import run | |
import shlex | |
run(shlex.split(_cmd_install_font), capture_output=False, check=False) | |
import matplotlib.font_manager as fm | |
if hasattr(fm, 'createFontList'): | |
thisfonts = fm.findSystemFonts(fontpaths=[".fonts"]) | |
fm.fontManager.ttflist.extend(fm.createFontList(thisfonts)) | |
else: | |
fm.fontManager.addfont(f".fonts/{_FONT}") | |
import matplotlib.pyplot as plt | |
plt.rcParams["font.family"] = _FAMILY | |
### 주의: unicode_minus=False 라도 set_xscale('log') 에서는 does not have a glyph for '\u2212' 발생 | |
plt.rcParams["axes.unicode_minus"] = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment