initial commit
This commit is contained in:
parent
54c4ac479c
commit
5e2ecbe419
52
matplotlib_utils.py
Normal file
52
matplotlib_utils.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import platform
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.font_manager as fm
|
||||||
|
from matplotlib import rc
|
||||||
|
'''
|
||||||
|
한글 폰트 설정
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Detect the operating system
|
||||||
|
os_name = platform.system()
|
||||||
|
def font_exists(font_name):
|
||||||
|
return any(font_name in f.name for f in fm.fontManager.ttflist)
|
||||||
|
|
||||||
|
font_name = 'NanumGothic'
|
||||||
|
if os_name == 'Darwin': # in case of MacOS
|
||||||
|
if font_exists('AppleGothic'):
|
||||||
|
font_name = 'AppleGothic'
|
||||||
|
elif os_name == 'Windows':
|
||||||
|
if font_exists('Malgun Gothic'):
|
||||||
|
font_name = 'Malgun Gothic'
|
||||||
|
|
||||||
|
if font_name == 'NanumGothic' and not font_exists('NanumGothic'):
|
||||||
|
raise ValueError("Please install NanumGothic font!")
|
||||||
|
|
||||||
|
# 한글 폰트 설치 함수
|
||||||
|
def install_font(os_name, font_name):
|
||||||
|
if os_name == 'Darwin': # in case of MacOS
|
||||||
|
if font_name == 'AppleGothic':
|
||||||
|
fm._rebuild()
|
||||||
|
elif os_name == 'Windows':
|
||||||
|
if font_name == 'Malgun Gothic':
|
||||||
|
pass
|
||||||
|
elif os_name == 'Linux':
|
||||||
|
'''
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install fonts-nanum*
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
rc('font', family=font_name)
|
||||||
|
plt.rcParams['axes.unicode_minus'] = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
plt.figure()
|
||||||
|
plt.plot([i**2 for i in range(5)])
|
||||||
|
plt.title('한글로 제목 달기')
|
||||||
|
plt.show()
|
||||||
56
temp_install_fonts.py
Normal file
56
temp_install_fonts.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import zipfile
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
def download_font(url, download_path):
|
||||||
|
"""Download the font zip file from the specified URL."""
|
||||||
|
print("Downloading Nanum Gothic font...")
|
||||||
|
response = requests.get(url, stream=True)
|
||||||
|
if response.status_code == 200:
|
||||||
|
with open(download_path, "wb") as file:
|
||||||
|
shutil.copyfileobj(response.raw, file)
|
||||||
|
print(f"Downloaded font to {download_path}")
|
||||||
|
else:
|
||||||
|
print("Failed to download font. Please check the URL.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
def extract_zip(file_path, extract_to):
|
||||||
|
"""Extract the zip file to the specified directory."""
|
||||||
|
print(f"Extracting {file_path} to {extract_to}...")
|
||||||
|
with zipfile.ZipFile(file_path, 'r') as zip_ref:
|
||||||
|
zip_ref.extractall(extract_to)
|
||||||
|
print(f"Extracted to {extract_to}")
|
||||||
|
|
||||||
|
def install_fonts(font_dir):
|
||||||
|
"""Install fonts into macOS Font Book directory."""
|
||||||
|
font_book_dir = Path.home() / "Library/Fonts"
|
||||||
|
print(f"Installing fonts to {font_book_dir}...")
|
||||||
|
for font_file in Path(font_dir).glob("*.ttf"):
|
||||||
|
shutil.copy(font_file, font_book_dir)
|
||||||
|
print(f"Installed {font_file.name}")
|
||||||
|
print("Fonts successfully installed.")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# URL for Nanum Gothic font download
|
||||||
|
font_url = "https://hangeul.naver.com/hangeul_static/webfont/zips/nanum-gothic.zip"
|
||||||
|
download_path = "/tmp/NanumFont_TTF_ALL.zip"
|
||||||
|
extract_path = "/tmp/NanumFont"
|
||||||
|
|
||||||
|
# Ensure the temporary directory exists
|
||||||
|
os.makedirs(extract_path, exist_ok=True)
|
||||||
|
|
||||||
|
# Steps to download, extract, and install
|
||||||
|
download_font(font_url, download_path)
|
||||||
|
extract_zip(download_path, extract_path)
|
||||||
|
install_fonts(extract_path)
|
||||||
|
|
||||||
|
# Clean up temporary files
|
||||||
|
print("Cleaning up temporary files...")
|
||||||
|
os.remove(download_path)
|
||||||
|
shutil.rmtree(extract_path)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user