Git Product home page Git Product logo

mpl-tc-fonts's Introduction

mpl-tc-fonts

mpl-tc-fonts

๐Ÿ‡น๐Ÿ‡ผ A package to solve the problem of "Tofu" in your matplotlib plots whenever you're trying to use Traditional Chinese characters in labels or texts.

Open in Colab README in Traditional Chinese

Other CJK Characters Version

Installation

Install mpl-tc-fonts with pip:

# Install from GitHub Repository for latest commit
$ pip install git+https://github.com/Hsins/mpl-tc-fonts.git

The package installer pip will install this package from the mpl-tc-fonts repository to your local python environment. Please see the FAQ section for more information and troubleshooting.

Usage

Quick Start

The easiest way to use this package is just import the package after installation. It links the fonts inside package folder to the matplotlib font manager and the Traditional Chinese characters will be properly displayed in your plots.

import matplotlib.pyplot as plt
import mpl_tc_fonts

names = ['ๅˆ†้กž A', 'ๅˆ†้กž B', 'ๅˆ†้กž C']
values = [1, 10, 100]

plt.figure(figsize=(9, 3))

plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('ๅˆ†้กž่ณ‡ๆ–™ๅœ–')
plt.show()

[NOTE] The default font would set to be ๆ€ๆบๅฎ‹้ซ”๏ผˆNoto Serif CJK TC๏ผ‰.

More Features

import mpl_tc_fonts

# Copy the cwTeX fonts into matplotlib folder
font_tool.load_font('cwtex', 'copy')

# Set "cwTeX Q Kai" to be the display font
font_tool.set_font('cwTeX Q Kai')

# Print out current font in use
font_tool.show_font_setting()

# Print out the list of the avaiable font-family name
print(font_tool.scan_font('ๅœ‹'))

There are some functions to help users qucik setup the fonts:

  • mpl_tc_fonts.load_font(folder, method) would install the given fonts.
    • folder can be noto (default) or cwtex
    • method can be link (default) or copy
  • mpl_tc_fonts.set_font(font) would set the given font to display the texts. There are 7 different fonts in this package.
    • Noto Sans CJK TC: ๆ€ๆบ้ป‘้ซ”
    • Noto Serif CJK TC: ๆ€ๆบๅฎ‹้ซ”
    • cwTeX Q Ming: cwTeX ไธญๆ˜Ž้ซ”
    • cwTeX Q Kai: cwTeX ไธญๆฅท้ซ”
    • cwTeX Q Yuan: cwTeX ไธญๅœ“้ซ”
    • cwTeX Q Fangsong: cwTeX ไปฟๅฎ‹้ซ”
    • cwTeX Q Hei: cwTeX ็ฒ—้ป‘้ซ”
  • mpl_tc_fonts.scan_font(char) return the list of avaiable fonts in the FontList of matlibplot. The given char is used to check whether glyph could be found in that font or not.
  • mpl_tc_fonts.show_font_setting() print out current font in use.

FAQ

[ Q ] What's the difference between copy and link options in the load_font() method?

TBD

License

Licensed under the GPL-3.0 License, Copyright ยฉ 2020-present Hsins.

mpl-tc-fonts's People

Contributors

hsins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mpl-tc-fonts's Issues

Translations of README.

Translate the README

People use CJK characters from Taiwan, China, Japan, and Korea. It would be helpful to translate the README file into languages used by them. Provide the locale codes of those languages:

  • ja
  • ko
  • zh-cn
  • zh-tw

Steps to complete the translation

  1. Fork this repository.
  2. Copy the README file to the translations folder from the root folder and rename it as the format README.{CODE}.md. e.g. README.zh-tw.md
  3. Create the Pull Request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.