Dragon Arrow written by Tatsuya Nakaji, all rights reserved animated-dragon-image-0164

python matplotlibのインストール

updated on 2019-05-07

イメージ

python matplotlibのインストール


初めに: Matplotlibは、プログラミング言語Pythonおよびその科学計算用ライブラリNumPyのためのグラフ描画ライブラリである。(wikipedia)


手順1. matplotlibのインストール

pip install matplotlib


手順2. 設定ファイル(=matplotlibrc)を編集する(これしないと動かない)

$ python
Python 3.7.3 (default, May  7 2019, 14:28:48) 
[Clang 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib as mpl
>>> print(mpl.get_configdir()) Matplotlib設定保存用ディレクトリ確認
~/.matplotlib
>>> print(mpl.matplotlib_fname()) 適用されているmatplotlibrcの確認
~/matplotlib/mpl-data/matplotlibrc
>>>


なるほど!このmpl-dataってディレクトリに「設定ファイル(=matplotlibrc)」が入っているのですね!!!

$ open matplotlibrc

すると、ついに設定ファイル(.txt)が姿を表します!
こんな感じ

### MATPLOTLIBRC FORMAT

# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc.  If you edit it
# there, please note that it will be overwritten in your next install.
# If you want to keep a permanent local copy that will not be
# overwritten, place it in the following location:
# unix/linux:
#     $HOME/.config/matplotlib/matplotlibrc or
#     $XDG_CONFIG_HOME/matplotlib/matplotlibrc (if $XDG_CONFIG_HOME is set)
# other platforms:
#     $HOME/.matplotlib/matplotlibrc
#
# See http://matplotlib.org/users/customizing.html#the-matplotlibrc-file for
# more details on the paths which are checked for the configuration file.
#
# This file is best viewed in a editor which supports python mode
# syntax highlighting. Blank lines, or lines starting with a comment
# symbol, are ignored, as are trailing comments.  Other lines must
# have the format
#    key : val # optional comment
#
# Colors: for the color values below, you can either use - a
# matplotlib color string, such as r, k, or b - an rgb tuple, such as
# (1.0, 0.5, 0.0) - a hex string, such as ff00ff - a scalar
# grayscale intensity such as 0.75 - a legal html color name, e.g., red,
# blue, darkslategray

#### CONFIGURATION BEGINS HERE

# The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
# Template.
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'.
backend      : macos

...

この最後の行の 
backend : macos
を、

backend : TkAgg

にしてあげる。

これで完了!!