Skip to main content

Fonts manager for matplotlib

Project description

中文文档

mplfonts

Fonts manager for matplotlib

This is a python package and command line tool to manage your matplotlib fonts. You can easily resolve the "tofu" problem when plotting with CJK(Chinese, Japanese, Korean) languages.

Installation

You can install mplfonts with pip

$ pip install mplfonts

Quickstart

You can just run one command to solve the "tofu" problem:

$ mplfonts quickstart

After that, try to use matplotlib to plot an image with CJK text, it should be normal.

Now you can enjoy it.

Usage

This package's aim is not only to solve "tofu" problem, but also to manage matplotlib fonts. When you installed mplfonts, there are some open-source CJK fonts already included, they are:

  • Noto Sans Mono CJK SC
  • Noto Serif CJK SC
  • Noto Sans CJK SC
  • Source Han Serif SC
  • Source Han Mono SC If you have finished the quickstart, You can shift fonts in you script like:
from mplfonts import use_font

use_font('Noto Serif CJK SC')

# write your plotting code below

If you want to setup some custom fonts, you can install by command:

$ mplfonts install --update <your font file path>

Also, you can install all fonts in a directory(folder) by:

$ mplfonts install --update <your directory path>

Don't know what fonts is available? Don't worry, you can use mplfonts list to list all available fonts.

$ mplfonts list
DejaVu Sans Display:
/Users/clarmylee/Miniconda3/envs/mplfonts/lib/python3.6/site-packages/matplotlib-3.3.4-py3.6-macosx-10.9-x86_64.egg/matplotlib/mpl-data/fonts/ttf/DejaVuSansDisplay.ttf
---------------
DejaVu Sans:
/Users/clarmylee/Miniconda3/envs/mplfonts/lib/python3.6/site-packages/matplotlib-3.3.4-py3.6-macosx-10.9-x86_64.egg/matplotlib/mpl-data/fonts/ttf/DejaVuSans-BoldOblique.ttf
---------------
Source Han Mono SC:
/Users/clarmylee/Miniconda3/envs/mplfonts/lib/python3.6/site-packages/matplotlib-3.3.4-py3.6-macosx-10.9-x86_64.egg/matplotlib/mpl-data/fonts/ttf/SourceHanMonoSC-Regular.otf

...

It will show fonts' name and source file, and these names can be argument to pass to use_font function

By default, mplfonts quickstart will generate a matplotlibrc as the cache configuration, supporting CJK render, to replace your old one, the content of matplotlibrc is:

font.family:  sans-serif
font.sans-serif: Noto Sans CJK SC Regular, 思源等宽, Noto Serif CJK SC, 思源宋体, Noto Sans Mono CJK SC Regularsans-serif
axes.unicode_minus: False

It will preferentially use Noto Sans CJK SC Regular as the default font. If you install custom fonts from other source, and want it to be the first priority, you should add it to the leftmost end of font.sans-serif list, and then run $ mplfonts updaterc <your matploblibrc path> to set it as your global cache rc.

Fonts Source

You can access some open-source fonts from google and adobe, here is some resource:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mplfonts-0.0.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

mplfonts-0.0.2-py3-none-any.whl (79.9 MB view details)

Uploaded Python 3

File details

Details for the file mplfonts-0.0.2.tar.gz.

File metadata

  • Download URL: mplfonts-0.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.13

File hashes

Hashes for mplfonts-0.0.2.tar.gz
Algorithm Hash digest
SHA256 461f54e243d2709ae6f93b437d10145d05741977aad77dd938f237977d7e6e4d
MD5 afe0b3eea1f90cbd4bffda2dfa0bde8f
BLAKE2b-256 3e6b5162c58bb4a7a01a1a9ebea8ae310af485096c9d86710e83869cd3b71fc0

See more details on using hashes here.

File details

Details for the file mplfonts-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mplfonts-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 79.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.13

File hashes

Hashes for mplfonts-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c8c33514008a9bf3e6d80613d59f89f58e81affb0abfdaf7a924e0e216d16b2
MD5 4c0786c32d210fdc240bfe7acce0211e
BLAKE2b-256 39f35bc856b43508928a7e30984995b0bb5c662e51aed01578f121e12e6f3f0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page