Coder Social home page Coder Social logo

japanize-matplotlib's Introduction

PyPI version

japanize-matplotlib

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

利用方法

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

import matplotlib.pyplot as plt
import japanize_matplotlib

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

demo

インストール

# pipenvで
pipenv install japanize-matplotlib

# またはpipで
pip install japanize-matplotlib

# condaで
conda install -c uehara1414 japanize-matplotlib

利用フォント

IPAフォントのIPAexゴシック(Ver.003.01)を利用しています。 利用にあたってはIPAフォントライセンスv1.0に同意してください。

FAQ

import japanize_matplotlib したのに日本語表示になりません #1

import japanize_matplotlib してから matplotlib でグラフを描画するまでにフォントの設定が変わる処理が入っていると、日本語表示がなされない可能性があります。

例えば、seaborn を利用している場合であれば sns.set() などで描画フォントが seaborn のデフォルトに上書きされ、日本語表示がされなくなります。

sns.set(font="IPAexGothic") のように利用フォントに IPAexGothic を設定するか、フォント上書き後に japanize_matplotlib.japanize() を利用するなどで日本語表示できるはずです。

import のみして利用されないコードなのでフォーマッターに消されてしまいます

リンターなどの警告が気になる・コードを消される方向けに japanize_matplotlib.japanize() メソッドの実行でも import 時と同じくフォントを設定できるようになっています。 無意味な実行になりますが、時と場合に応じて実行してください。

もしくはリンターごとに無視させる設定をすることで対応できるはずです。# noqa などで設定してください。

なぜインストール時は japanize-matplotlib で import 時は japanize_matplotlib なのですか?

チェインケースが読みやすく好きだからです。import時にはチェインケースは利用できないのでスネークケースになっています。

japanize-matplotlib's People

Contributors

elnikkis avatar pesuchin avatar uehara1414 avatar upura avatar vaaaaanquish avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

japanize-matplotlib's Issues

Pathlib への依存をなくす

Pathlib は Python3.4 から実装されたモジュールであり、このモジュールに依存している限り 3.4 以前の実行環境にて利用できないため。

`plt.style.use()`を使う場合の挙動

import japanize_matplotlibの位置によってエラーが発生する。

エラーが発生するケース:

import matplotlib.pyplot as plt
import japanize_matplotlib
plt.style.use('dark_background')

エラーが発生しないケース:

import matplotlib.pyplot as plt
plt.style.use('dark_background')
import japanize_matplotlib

deprecation warning: font_manager.createFontList()

Describe the issue

japanize-matplotlib uses font_manager.createFontList() now.
However, Matplotlib will remove the function at version of 3.4 or 3.5.
Matplotlib suggests to use font_manager.addfont() instead.

To reproduce the issue

$ pip install japanize-matplotlib
$ python -c "from matplotlib import pyplot as plt; import japanize_matplotlib"
/Users/amedama/.virtualenvs/py37/lib/python3.7/site-packages/japanize_matplotlib/__init__.py:13: MatplotlibDeprecationWarning: 
The createFontList function was deprecated in Matplotlib 3.2 and will be removed two minor releases later. Use FontManager.addfont instead.
  font_list = font_manager.createFontList(font_files)

(FYI) My environment

$ sw_vers     
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G3020
$ python -V                                                                   
Python 3.7.7
$ pip list | grep -i matplotlib
japanize-matplotlib      1.0.5       
matplotlib               3.2.1       

[Proposal] Python 3.12以降への対応

大変便利なパッケージの開発、ありがとうございます。

問題

Python 3.12.x で、pip installを利用してこちらのパッケージを利用しようとするとno module errorで動作しない

再現

  • Python 3.12
  • japanize_matplotlib 1.1.3

仮想環境の作成

$pipenv --python 3.12
$pipenv install matplotlib japanize_matplotlib

ソースコード

import japanize_matplotlib

エラーメッセージ

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'distutils'

原因

https://peps.python.org/pep-0632/#backwards-compatibility
distutilsが3.12以降、削除されたのでno module errorを引き起こします。

提案

こちらの質問の回答のように、distutilsへの依存を削除すべきかと思います。
https://teratail.com/questions/ispptkd2y6ai7t

必要であればPRを作成します。
以上、よろしくお願いします。

Anacondaでのアーキテクチャー指定に関するご質問およびconda-forgeチャンネル経由のインストールについて

Anacondaでのアーキテクチャー指定に関するご質問およびconda-forgeチャンネル経由のインストールについて

非常に有用なPythonパッケージの開発ありがとうございます。

anacondaを用いたインストール方法をすでに提供いただいている (#18) かと思うのですが、
アーキテクチャをMac OSのみに指定しておられると思います。

こちら特別な理由等ございますでしょうか。

pip installしたパッケージはWindows, linuxで問題なく動作しますので疑問に思い、ご質問差し上げました。

もし上記に特別な理由等ございませんでしたら、私のほうでアーキテクチャ依存を外した上でconda-forgeチャンネル経由で当該パッケージをインストールできるようにさせていただきたいのですが、ご承認いただけませんでしょうか。

ライセンス上不要かと存じますが、念の為ご連絡差し上げました。

お忙しいところ大変恐縮ですが、お返事いただけますと幸いです。
何卒よろしくお願いいたします。

import しても豆腐のままになる問題

素敵なものをありがとうございます。早速使ってみたのですが、importしても日本語が表示されません。二台のMacで試してみましたがどちらもだめでした。

試したときのnotebookはこちらになります。 念の為。
https://github.com/masakiaota/study/blob/master/my_cheatsheet/Seaborn.ipynb?short_path=1b80cf8

また、matplotlib等のバージョンは以下のようになっています。

jupyterlab 0.35.3
japanize-matplotlib 1.0.4
matplotlib 3.0.1

IPAフォントを自分でインストールいないと行けないのでしょうか?

japanize-matplotlib経由でmatplotlibを呼び出せるようにする

以下のようなイメージで、japanize-matplotlib経由でmatplotlibを呼び出せるようにすると、japanize-matplotlibのimport文がフォーマッターに消されずに済むかと思います。

from japanize_matplotlib import pyplot as plt

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

1.0.5 リリース

TODO

  • HISTORY.md 作成
    • @elnikkis さんの修正を追加
    • README.md に反映
  • リリース
    • setup.py 書き換え
  • Qiitaへ修正を追記

import時にエラー"illegal type for path parameter"が出る

問題

import時に次のようなエラーが出ます。

Traceback (most recent call last):
  File "test_japanize_matplotlib.py", line 6, in <module>
    import japanize_matplotlib
  File "[...]/japanize-matplotlib/japanize_matplotlib/__init__.py", line 12, in <module>
    font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
  File "/usr/lib/python3/dist-packages/matplotlib/font_manager.py", line 343, in findSystemFonts
    files = list_fonts(path, fontexts)
  File "/usr/lib/python3/dist-packages/matplotlib/font_manager.py", line 179, in list_fonts
    return cbook.listFiles(directory, pattern)
  File "/usr/lib/python3/dist-packages/matplotlib/cbook.py", line 1178, in listFiles
    for dirname, dirs, files in os.walk(root):
  File "/usr/lib/python3.5/os.py", line 371, in walk
    scandir_it = scandir(top)
TypeError: scandir: illegal type for path parameter

pathlibが使えない関数が呼ばれていることが原因のようです。

環境

  • japanize-matplotlib (1.0.4)
  • matplotlib (2.0.0)
  • Python 3.5.3
  • WSL上のDebian 9.9

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.