回答編集履歴

1

追記

2020/01/10 07:09

投稿

quickquip
quickquip

スコア11051

test CHANGED
@@ -19,3 +19,63 @@
19
19
  ```
20
20
 
21
21
  を実行してみてください。グラフがでないはずですよ。
22
+
23
+
24
+
25
+ ----
26
+
27
+
28
+
29
+ `%matplotlib inline` は、
30
+
31
+
32
+
33
+ [https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-matplotlib](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-matplotlib) に
34
+
35
+
36
+
37
+ > This function lets you activate matplotlib interactive support at any point during an IPython session. It does not import anything into the interactive namespace.
38
+
39
+
40
+
41
+ とへ明記されている通り、matplotlib のインタラクティブサポートを有効化するためのコマンドです。
42
+
43
+
44
+
45
+ ----
46
+
47
+
48
+
49
+ 例えば`jupyter console`コマンドなどでJupyterを動かした場合、コンソールで動きますから`%matplotlib inline`をしてもコンソールに画像が出ないので意味がありません。
50
+
51
+
52
+
53
+ macOS上では、そこでコード`plt.plot(...)`を実行すると画像がテンポラリに保存されてプレビューアプリケーションが起動されます。
54
+
55
+
56
+
57
+ `%matplotlib osx`してからコード`plt.plot(...)`を実行すると**Pythonが**ウィンドウを出して画像を表示してくれます。
58
+
59
+
60
+
61
+ ----
62
+
63
+
64
+
65
+ 例えば`jupyter qtconsole`コマンドでJupyterを動かした場合、画像が表示できるコンソールで動きますから`%matplotlib inline`をすると`plt.plot(...)`の結果を画像として表示するようですね。
66
+
67
+ [https://stackoverflow.com/questions/38128640/use-both-matplotlib-inline-and-qt-in-jupyter-notebook#answer-38129646](https://stackoverflow.com/questions/38128640/use-both-matplotlib-inline-and-qt-in-jupyter-notebook#answer-38129646)
68
+
69
+
70
+
71
+ 他のGUIライブラリのqtやtkが使えるようにビルドされたPythonを使っていれば、`%matplotlib qt`とか`%matplotlib tk`というような選択肢もあると思います。
72
+
73
+
74
+
75
+ ----
76
+
77
+
78
+
79
+ 実際やってみるとこのスイッチがどこかに保管されていて、今何が有効なのか? がつかみづらかったです。
80
+
81
+ 確かに、1度目はインライン表示されないが2度実行すると表示される、みたいなことも、特にinline指定しなくても表示される、みたいなことも起こりました。