「Matplotlib tips」の版間の差分
提供: Eospedia
行1: | 行1: | ||
− | == 参考文献 == | + | == 参考文献(全般) == |
* [https://matplotlib.org/tutorials/index.html 公式チュートリアル] | * [https://matplotlib.org/tutorials/index.html 公式チュートリアル] | ||
* [https://qiita.com/skotaro/items/08dc0b8c5704c94eafb9 早く知っておきたかったmatplotlibの基礎知識、あるいは見た目の調整が捗るArtistの話] | * [https://qiita.com/skotaro/items/08dc0b8c5704c94eafb9 早く知っておきたかったmatplotlibの基礎知識、あるいは見た目の調整が捗るArtistの話] | ||
行14: | 行14: | ||
始めにinlineにしておいて途中からwidgetに変えるとかは無理。最初から冒頭でwidgetにしておく必要あり。 | 始めにinlineにしておいて途中からwidgetに変えるとかは無理。最初から冒頭でwidgetにしておく必要あり。 | ||
+ | |||
+ | == 複数プロット == | ||
+ | === 参考文献 === | ||
+ | * https://matplotlib.org/devdocs/gallery/subplots_axes_and_figures/subplots_demo.html | ||
+ | |||
+ | === 具体例1 === | ||
+ | * 縦に3つのグラフを並べて、x軸の目盛りとラベルは一番下のみに表示 | ||
+ | <pre> | ||
+ | fig, ax = plt.subplots(nrows=3, ncols=1, figsize=figsize, dpi=dpi, sharex=True) | ||
+ | ax[0].plot(epoch, gen_loss) | ||
+ | ax[0].set_ylabel('Generator loss') | ||
+ | ax[1].plot(epoch, kld) | ||
+ | ax[1].set_ylabel('KLD') | ||
+ | ax[2].plot(epoch, total_loss) | ||
+ | ax[2].set_ylabel('Total loss') | ||
+ | ax[2].set_xlabel('Epoch') | ||
+ | </pre> | ||
== 3Dプロット == | == 3Dプロット == |
2020年10月29日 (木) 10:08時点における版
参考文献(全般)
JupyterLabでインタラクティブプロット
- 下準備
- ipympl( https://github.com/matplotlib/ipympl )をインストール
- 使い方
- ノートブックの冒頭で以下のマジックコマンドをたたく
%matplotlib widget
始めにinlineにしておいて途中からwidgetに変えるとかは無理。最初から冒頭でwidgetにしておく必要あり。
複数プロット
参考文献
具体例1
- 縦に3つのグラフを並べて、x軸の目盛りとラベルは一番下のみに表示
fig, ax = plt.subplots(nrows=3, ncols=1, figsize=figsize, dpi=dpi, sharex=True) ax[0].plot(epoch, gen_loss) ax[0].set_ylabel('Generator loss') ax[1].plot(epoch, kld) ax[1].set_ylabel('KLD') ax[2].plot(epoch, total_loss) ax[2].set_ylabel('Total loss') ax[2].set_xlabel('Epoch')
3Dプロット
Axes3D
- インポート
from mpl_toolkits.mplot3d import Axed3D import matplotlib.pyplot as plt
- 使い方
fig = plt.figure() ax = fig.add_subplot(111, projection='3d')
- axはAxes3Dというクラスのインスタンスになっていて、3Dプロット用のメソッドを持っている。
- %matplotlib widget と一緒に使うと、3Dプロットの回転とかがマウスドラッグで可能。