Matplotlib, Seaborn ํ•œ๊ธ€ Font error

Lยท2022๋…„ 9์›” 26์ผ
0
post-thumbnail
post-custom-banner

๋…์ž ๋Œ€์ƒ๐Ÿ“ฃ

๐Ÿ‘‰ Ubuntn ํ™˜๊ฒฝ์—์„œ python์œผ๋กœ B/E ๊ฐœ๋ฐœ์ค‘์ด์‹  ๋ถ„
๐Ÿ‘‰ Jinja2 template์œผ๋กœ ์›น ๋งŒ๋“œ์‹œ๋Š” ๋ถ„


์ถœ๊ฐ„ ์ด์œ โ“

matplotlib, seaborn ์‚ฌ์šฉ ์ค‘, ํ•œ๊ธ€ ๊นจ์ง ํ˜„์ƒ ๋ฐœ๊ฒฌ


๋ฌธ์ œ ํŒŒ์•…๐Ÿ”

UserWarning: Glyph 46020 (\N{HANGUL SYLLABLE }) missing from current font.
Q: Ubuntu ์œ„์— ๊ตฌ์ถ•ํ•œ B/E ์„œ๋ฒ„์—์„œ matplotlib ์‚ฌ์šฉ ์‹œ,
   ํ•œ๊ธ€์ด ๊นจ์ง‘๋‹ˆ๋‹ค...
   ๊ตฌ๊ธ€๋งํ–ˆ๋Š”๋ฐ plt.rcParams['font.family']๋กœ ์„ค์ •ํ•ด๋„
   ํ•œ๊ธ€์ด ๊ณ„์† ๊นจ์ ธ์žˆ์–ด์š”..๐Ÿ˜ฅ๐Ÿ˜ฅ๐Ÿ˜ฅ๐Ÿ˜ฅ

๋ฌธ์ œ ํ•ด๊ฒฐ๐ŸŽŠ

A: ์šฐ์„  matplot๋งŒ ์‚ฌ์šฉ์ค‘์ธ๊ฒŒ ํ™•์‹คํ•œ์ง€ ๋‹ค์‹œ ํ•œ ๋ฒˆ ํ™•์ธํ•ด๋ณด์„ธ์š”โ—

   ๋งŒ์•ฝ seaborn์„ ๋ฒ ์ด์Šค๋กœ ์‚ฌ์šฉ์ค‘์ด์‹œ๋ผ๋ฉด matplot์ด ์•„๋‹Œ
   seaborn์—์„œ ํฐํŠธ ์„ค์ •์„ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
   
   Ubuntu ํ™˜๊ฒฝ์—์„œ ํฐํŠธ ์„ค์น˜ ๋ฐฉ๋ฒ•์€ ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค~๐Ÿ˜๐Ÿ˜€
   ํ•˜๋‹จ์˜ ๋‚ด์šฉ์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ด Disgustingํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์‹ญ์‹œ์˜คโ—โ—
  1. (์„œ๋น„์Šค) ๋‚˜๋ˆ” ํฐํŠธ ์„ค์น˜ ๋ฐ ์บ์‰ฌ ์‚ญ์ œ

    $ sudo apt-get update
    $ sudo apt-get install fonts-nanum*
    
    # ํ•˜๋‹จ์€ ์บ์‰ฌ ์‚ญ์ œ ์ปค๋งจ๋“œ์ด๋ฉฐ, ํ•„์ˆ˜ ์ปค๋งจ๋”ฉ ์‚ฌํ•ญ์€ ์•„๋‹˜!
    $ sudo fc-cache -fv
  2. (์„œ๋น„์Šค) ๋‚˜๋ˆ” ํฐํŠธ ๋ณต์‚ฌ

    # B/E์—์„œ ์‚ฌ์šฉ์ค‘์ธ python๋ฒ„์ „ ํ™•์ธํ•˜์—ฌ python ํ„ฐ๋ฏธ๋„ ์ง„์ž….
    >>> import matplotlib
    >>> matplotlib.__file__
    '/usr/anaconda3/lib/python3.7/site-packages/matplotlib/__init__.py'
  3. (์„œ๋น„์Šค) ๋‚˜๋ˆ” ํฐํŠธ ๋ณต์‚ฌ

    # ์‹œ์Šคํ…œ์— ์œ„์น˜ํ•œ ๋‚˜๋ˆ” ํฐํŠธ๋ฅผ matplotlib ๋กœ ๋ณต์‚ฌ
    $ sudo cp /usr/share/fonts/truetype/nanum/Nanum* /usr/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/
  4. ํฐํŠธ ์ ์šฉ #1

    ~
    # seaborn ์‚ฌ์šฉ์ค‘์ผ ๊ฒฝ์šฐ.
    sns.set(rc = {'font.family':'NanumGothicCoding'})
    sns.joinplot(x=x, y=y, data=data, kind="reg")
    plt.savefig()
    ~
  5. ํฐํŠธ ์ ์šฉ #2

    ~
    # matplotlib๋งŒ ์‚ฌ์šฉ์ค‘์ผ ๊ฒฝ์šฐ.
    plt.rcParams['font.family'] = 'NanumGothicCoding'
    plt.savefig()
    ~

์œ„ ๋‹จ๊ณ„๋กœ ํ•ด๊ฒฐ ๋ถˆ๊ฐ€ ์‹œ, ํ•˜๋‹จ์˜ ๋‹จ๊ณ„๋ฅผ ์ถ”๊ฐ€๋กœ ์‹œํ–‰ํ•ด์ฃผ์„ธ์š”.

  1. ํฐํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ ๊ฒ€์ƒ‰
    >>> import matplotlib
    >>> matplotlib.matplotlib_fname()
    /usr/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
  2. ํฐํŠธ ์„ค์ • ํŒŒ์ผ ์ˆ˜์ •
    # matplotlibrc ํŒŒ์ผ์—์„œ "font.family ๋ถ€๋ถ„์„ ์ฐพ์•„ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”"
    $ vi /usr/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
    ~
    #font.family : NanumGothic
    ~
  3. matplotlib ์บ์‰ฌ ํŒŒ์ผ ์‚ญ์ œ
    # ์ถœ๋ ฅ๊ฒฐ๊ณผ์˜ ์บ์‰ฌ ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ์ด๋™ํ•˜์—ฌ
    # "tex.cache", "fontlist-v310.json" ํŒŒ์ผ ์‚ญ์ œ
    >>> import matplotlib
    >>> matplotlib.get_cachedir()
    [์บ์‰ฌ ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฒฝ๋กœ]
profile
๋ฐ์ดํ„ฐ ์š”๋ฆฌ์‚ฌ
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€