matplotlib-fontja


Namematplotlib-fontja JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
Summarymatplotlibを日本語表示に対応させます。
upload_time2025-02-13 18:00:07
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # matplotlib-fontja

[![CI status](https://github.com/ciffelia/matplotlib-fontja/actions/workflows/ci.yaml/badge.svg)](https://github.com/ciffelia/matplotlib-fontja/actions/workflows/ci.yaml)
[![PyPI project](https://badge.fury.io/py/matplotlib-fontja.svg)](https://pypi.org/project/matplotlib-fontja/)
[![conda-forge](https://img.shields.io/conda/vn/conda-forge/matplotlib-fontja.svg)](https://anaconda.org/conda-forge/matplotlib-fontja)

matplotlibを日本語表示に対応させます。

[uehara1414](https://github.com/uehara1414)さんの[japanize-matplotlib](https://github.com/uehara1414/japanize-matplotlib)をフォークし、Python 3.12以降でも動作するよう修正したものです。変更点の詳細については[CHANGELOG](https://github.com/ciffelia/matplotlib-fontja/blob/master/CHANGELOG.md)をお読みください。

## 利用方法

matplotlibをimportした後、matplotlib_fontjaをimportします。

```python
import matplotlib.pyplot as plt
import matplotlib_fontja

plt.plot([1, 2, 3, 4])
plt.xlabel('簡単なグラフ')
plt.show()
```

![demo](https://raw.githubusercontent.com/ciffelia/matplotlib-fontja/master/demo.png)

## インストール

```sh
# pipを使う場合
pip install matplotlib-fontja

# uvを使う場合
uv add matplotlib-fontja

# Ryeを使う場合
rye add matplotlib-fontja

# Pipenvを使う場合
pipenv install matplotlib-fontja

# Poetryを使う場合
poetry add matplotlib-fontja

# Condaを使う場合
conda install conda-forge::matplotlib-fontja
```

## 利用フォント

IPAexゴシック (Ver.004.01) を利用しています。
利用にあたっては[IPAフォントライセンスv1.0](https://github.com/ciffelia/matplotlib-fontja/blob/master/src/matplotlib_fontja/fonts/IPA_Font_License_Agreement_v1.0.txt)に同意してください。

## FAQ

### `import matplotlib_fontja`したのに日本語が表示されません

`import matplotlib_fontja`してからグラフを描画するまでにフォントの設定が変わる処理が入っている可能性があります。

例えば、seabornを使用していると`sns.set_theme()`などでフォントがseabornのデフォルトに上書きされてしまいます。

以下のように、フォント上書き後に`matplotlib_fontja.japanize()`を実行してください。

```python
sns.set_theme()
matplotlib_fontja.japanize()
```

seabornの場合は、`sns.set_theme(font="IPAexGothic")`として`IPAexGothic`を使用するよう設定することもできます。

### `import matplotlib_fontja`に対してリンターの警告(F401)が出ます/フォーマッターに消されてしまいます

importした`matplotlib_fontja`を使用していないため、不要なimportと誤判定されています。以下のように`noqa`で無効化してください。

```python
import matplotlib_fontja  # noqa: F401
```

あるいは、`matplotlib_fontja.japanize()`を使用すれば未使用と判定されません。無意味な実行になりますが、import直後などに追加して警告を消すこともできます。

```python
import matplotlib_fontja

matplotlib_fontja.japanize()
```

### IPAexゴシック以外のフォントを使いたいです

matplotlibの標準機能で任意のフォントを使用できます。matplotlib-fontjaは不要です。以下はNoto Sans Japaneseを使う例です。

```python
import matplotlib.font_manager
import matplotlib.pyplot as plt

# フォントファイルを読み込み
matplotlib.font_manager.fontManager.addfont(
    "/path/to/NotoSansJP-Regular.ttf"
)

# 読み込んだフォントを使用するよう設定
matplotlib.rc("font", family="Noto Sans JP")

plt.plot([1, 2, 3, 4])
plt.xlabel('簡単なグラフ')
plt.show()
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "matplotlib-fontja",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "Ciffelia <mc.prince.0203@gmail.com>",
    "keywords": null,
    "author": null,
    "author_email": "uehara1414 <akiya.noface@gmail.com>, Ciffelia <mc.prince.0203@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/92/f7/698c8209e6aa418b210655c5bd74d10a13282d7dc2932348bc3b378dd897/matplotlib_fontja-1.0.1.tar.gz",
    "platform": null,
    "description": "# matplotlib-fontja\n\n[![CI status](https://github.com/ciffelia/matplotlib-fontja/actions/workflows/ci.yaml/badge.svg)](https://github.com/ciffelia/matplotlib-fontja/actions/workflows/ci.yaml)\n[![PyPI project](https://badge.fury.io/py/matplotlib-fontja.svg)](https://pypi.org/project/matplotlib-fontja/)\n[![conda-forge](https://img.shields.io/conda/vn/conda-forge/matplotlib-fontja.svg)](https://anaconda.org/conda-forge/matplotlib-fontja)\n\nmatplotlib\u3092\u65e5\u672c\u8a9e\u8868\u793a\u306b\u5bfe\u5fdc\u3055\u305b\u307e\u3059\u3002\n\n[uehara1414](https://github.com/uehara1414)\u3055\u3093\u306e[japanize-matplotlib](https://github.com/uehara1414/japanize-matplotlib)\u3092\u30d5\u30a9\u30fc\u30af\u3057\u3001Python 3.12\u4ee5\u964d\u3067\u3082\u52d5\u4f5c\u3059\u308b\u3088\u3046\u4fee\u6b63\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u5909\u66f4\u70b9\u306e\u8a73\u7d30\u306b\u3064\u3044\u3066\u306f[CHANGELOG](https://github.com/ciffelia/matplotlib-fontja/blob/master/CHANGELOG.md)\u3092\u304a\u8aad\u307f\u304f\u3060\u3055\u3044\u3002\n\n## \u5229\u7528\u65b9\u6cd5\n\nmatplotlib\u3092import\u3057\u305f\u5f8c\u3001matplotlib_fontja\u3092import\u3057\u307e\u3059\u3002\n\n```python\nimport matplotlib.pyplot as plt\nimport matplotlib_fontja\n\nplt.plot([1, 2, 3, 4])\nplt.xlabel('\u7c21\u5358\u306a\u30b0\u30e9\u30d5')\nplt.show()\n```\n\n![demo](https://raw.githubusercontent.com/ciffelia/matplotlib-fontja/master/demo.png)\n\n## \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n\n```sh\n# pip\u3092\u4f7f\u3046\u5834\u5408\npip install matplotlib-fontja\n\n# uv\u3092\u4f7f\u3046\u5834\u5408\nuv add matplotlib-fontja\n\n# Rye\u3092\u4f7f\u3046\u5834\u5408\nrye add matplotlib-fontja\n\n# Pipenv\u3092\u4f7f\u3046\u5834\u5408\npipenv install matplotlib-fontja\n\n# Poetry\u3092\u4f7f\u3046\u5834\u5408\npoetry add matplotlib-fontja\n\n# Conda\u3092\u4f7f\u3046\u5834\u5408\nconda install conda-forge::matplotlib-fontja\n```\n\n## \u5229\u7528\u30d5\u30a9\u30f3\u30c8\n\nIPAex\u30b4\u30b7\u30c3\u30af (Ver.004.01) \u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002\n\u5229\u7528\u306b\u3042\u305f\u3063\u3066\u306f[IPA\u30d5\u30a9\u30f3\u30c8\u30e9\u30a4\u30bb\u30f3\u30b9v1.0](https://github.com/ciffelia/matplotlib-fontja/blob/master/src/matplotlib_fontja/fonts/IPA_Font_License_Agreement_v1.0.txt)\u306b\u540c\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\n## FAQ\n\n### `import matplotlib_fontja`\u3057\u305f\u306e\u306b\u65e5\u672c\u8a9e\u304c\u8868\u793a\u3055\u308c\u307e\u305b\u3093\n\n`import matplotlib_fontja`\u3057\u3066\u304b\u3089\u30b0\u30e9\u30d5\u3092\u63cf\u753b\u3059\u308b\u307e\u3067\u306b\u30d5\u30a9\u30f3\u30c8\u306e\u8a2d\u5b9a\u304c\u5909\u308f\u308b\u51e6\u7406\u304c\u5165\u3063\u3066\u3044\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\n\n\u4f8b\u3048\u3070\u3001seaborn\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u3068`sns.set_theme()`\u306a\u3069\u3067\u30d5\u30a9\u30f3\u30c8\u304cseaborn\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u306b\u4e0a\u66f8\u304d\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002\n\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u30d5\u30a9\u30f3\u30c8\u4e0a\u66f8\u304d\u5f8c\u306b`matplotlib_fontja.japanize()`\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\n```python\nsns.set_theme()\nmatplotlib_fontja.japanize()\n```\n\nseaborn\u306e\u5834\u5408\u306f\u3001`sns.set_theme(font=\"IPAexGothic\")`\u3068\u3057\u3066`IPAexGothic`\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\n\n### `import matplotlib_fontja`\u306b\u5bfe\u3057\u3066\u30ea\u30f3\u30bf\u30fc\u306e\u8b66\u544a(F401)\u304c\u51fa\u307e\u3059/\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u306b\u6d88\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\n\nimport\u3057\u305f`matplotlib_fontja`\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u4e0d\u8981\u306aimport\u3068\u8aa4\u5224\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b`noqa`\u3067\u7121\u52b9\u5316\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\n```python\nimport matplotlib_fontja  # noqa: F401\n```\n\n\u3042\u308b\u3044\u306f\u3001`matplotlib_fontja.japanize()`\u3092\u4f7f\u7528\u3059\u308c\u3070\u672a\u4f7f\u7528\u3068\u5224\u5b9a\u3055\u308c\u307e\u305b\u3093\u3002\u7121\u610f\u5473\u306a\u5b9f\u884c\u306b\u306a\u308a\u307e\u3059\u304c\u3001import\u76f4\u5f8c\u306a\u3069\u306b\u8ffd\u52a0\u3057\u3066\u8b66\u544a\u3092\u6d88\u3059\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\n\n```python\nimport matplotlib_fontja\n\nmatplotlib_fontja.japanize()\n```\n\n### IPAex\u30b4\u30b7\u30c3\u30af\u4ee5\u5916\u306e\u30d5\u30a9\u30f3\u30c8\u3092\u4f7f\u3044\u305f\u3044\u3067\u3059\n\nmatplotlib\u306e\u6a19\u6e96\u6a5f\u80fd\u3067\u4efb\u610f\u306e\u30d5\u30a9\u30f3\u30c8\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002matplotlib-fontja\u306f\u4e0d\u8981\u3067\u3059\u3002\u4ee5\u4e0b\u306fNoto Sans Japanese\u3092\u4f7f\u3046\u4f8b\u3067\u3059\u3002\n\n```python\nimport matplotlib.font_manager\nimport matplotlib.pyplot as plt\n\n# \u30d5\u30a9\u30f3\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\nmatplotlib.font_manager.fontManager.addfont(\n    \"/path/to/NotoSansJP-Regular.ttf\"\n)\n\n# \u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30a9\u30f3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u8a2d\u5b9a\nmatplotlib.rc(\"font\", family=\"Noto Sans JP\")\n\nplt.plot([1, 2, 3, 4])\nplt.xlabel('\u7c21\u5358\u306a\u30b0\u30e9\u30d5')\nplt.show()\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "matplotlib\u3092\u65e5\u672c\u8a9e\u8868\u793a\u306b\u5bfe\u5fdc\u3055\u305b\u307e\u3059\u3002",
    "version": "1.0.1",
    "project_urls": {
        "Changelog": "https://github.com/ciffelia/matplotlib-fontja/blob/master/CHANGELOG.md",
        "Homepage": "https://github.com/ciffelia/matplotlib-fontja",
        "Issues": "https://github.com/ciffelia/matplotlib-fontja/issues",
        "Repository": "https://github.com/ciffelia/matplotlib-fontja.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0953021a48c3d9d662c3ff350d8cd029c01581a2ccf64c97caaed522faa8d721",
                "md5": "9436b31e807a13a0a77037edfcefa707",
                "sha256": "78217d465f44d5c67af00860f742befec1b39713c56484889e99be6c1d897c73"
            },
            "downloads": -1,
            "filename": "matplotlib_fontja-1.0.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9436b31e807a13a0a77037edfcefa707",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4168235,
            "upload_time": "2025-02-13T18:00:04",
            "upload_time_iso_8601": "2025-02-13T18:00:04.620178Z",
            "url": "https://files.pythonhosted.org/packages/09/53/021a48c3d9d662c3ff350d8cd029c01581a2ccf64c97caaed522faa8d721/matplotlib_fontja-1.0.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "92f7698c8209e6aa418b210655c5bd74d10a13282d7dc2932348bc3b378dd897",
                "md5": "d69ae073661c89680b00c45ed4ba8aec",
                "sha256": "23ec82ee445957409df0106aab477b4c43bb56d67e6e5fc8bcb8c7ede11f3ded"
            },
            "downloads": -1,
            "filename": "matplotlib_fontja-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d69ae073661c89680b00c45ed4ba8aec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4164108,
            "upload_time": "2025-02-13T18:00:07",
            "upload_time_iso_8601": "2025-02-13T18:00:07.340995Z",
            "url": "https://files.pythonhosted.org/packages/92/f7/698c8209e6aa418b210655c5bd74d10a13282d7dc2932348bc3b378dd897/matplotlib_fontja-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-13 18:00:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ciffelia",
    "github_project": "matplotlib-fontja",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "matplotlib-fontja"
}
        
Elapsed time: 3.12754s