LoginSignup
64
51

More than 5 years have passed since last update.

%matplotlib inlineを毎回書かなくて済む方法

Posted at

はじめに

jupyter notebookを使っていて、毎回
%matplotlib inline

と書いていましたが、
どうせいつも使うなら最初に設定しておくべきだと思いました。
本当の動機は、.ipynbを.pyとして使用したいときに、
get_ipythonのerrorが出るので、それを回避するための方法としてこのやり方を使いました。

解決方法

matplotlibのグラフを表示する

%matplotlib inline

を自動的に以下のようにして有効にします。

notebookのプロファイルを設定します。
もし設定をしていないようでしたら、以下のcommandで作成します。

ipython profile create

これでできた~/.ipython/profile_default/ipython_config.pyを編集します。

# lines of code to run at IPython startup.
# c.InteractiveShellApp.exec_lines = traitlets.Undefined
c.InteractiveShellApp.exec_lines = ['%matplotlib inline']

c.InteractiveShellApp.exec_lines = ['%matplotlib inline']の行を追加します。
あとはいつも通りnotebookを起動させれば自動的に%matplotlib inlineが有効になります。

64
51
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
64
51