- 追加された行はこの色です。
- 削除された行はこの色です。
[[FrontPage/Python/Scipy+Numpy]]
** ドキュメント [#o3ab97a0]
[[→公式リファレンス>http://turbare.net/transl/scipy-lecture-notes/intro/matplotlib/matplotlib.html]]
[[→docs>http://matplotlib.org/contents.html]]
[[→User's Guide>http://matplotlib.org/users/index.html]]
[[→Beginner’s Guide>http://matplotlib.org/users/beginner.html]]
[[→Advanced Guide>http://matplotlib.org/users/developer.html]]
** モジュールのインポート [#sce15176]
Matplotibを使ってグラフ描画するスクリプトは、PySideへそのまま移植したいと思っているので、pylabは使わず、pltとnpを使っていく.
import matplotlib.pyplot as plt
import numpy as np
** axes [#jb102e49]
ax = fig.add_subplot(1,1,1)
ax = fig.add_axes([0.15, 0.1, 0.7, 0.3]) : [left, bottom, width, height]
xtext = ax.set_xlabel(' frequency')
ytext = ax.set_ylabel(' Amplitude')
for ax in fig.axes:
ax.grid(True)
** fiugre, axes [#f171971a]
plt.close('all')
fig, ax = plt.subplots()
[[→Artist>http://matplotlib.org/1.3.0/users/artists.html]]
** fig.tight_layout() [#o2c92f56]
subplotの中身について、tickables, axis, labels, titlesの大きさを、タイトなレイアウトにしてくれる
[[→Tight Layout guide>http://matplotlib.org/1.4.1/users/tight_layout_guide.html]]
#ref(s-tight_layout0.jpg)
#ref(s-tight_layout1.jpg)
** Contour [#p5c671a5]
[[pyplot.contour>http://matplotlib.org/devdocs/api/pyplot_api.html#matplotlib.pyplot.contourf]]
contour(Z)
contour(Z, corner_mask=False, colors=(mpl_colors), alpha = (float), cmap=Colormap, NORM=Normalize, vmin=scalar, vmax=scalar, levels=[float], origin=['upper'|'lower'|'image'], extent=(x0,x1,y0,y1), locator=?, extend=補完?
contour(Z, cmap='hot')
**Colormap [#ebd62f48]
[[pyplot.Colormap>http://matplotlib.org/devdocs/api/colors_api.html#matplotlib.colors.Colormap]]
#ref(mpl_cmap.png,,20%)
[[→ Documenting the matplotlib colormaps>https://gist.github.com/endolith/2719900]]
** matplotlib.specgram [#l60e827c]
ガボールウェーブレットの結果をスペクトログラムの様に表示したいが、imshow()だと、縦横比がおかしくなったり、目盛が逆になったりして、1か月ぐらいはまっていた。そこで、matplotlib.specgramの中身を確認すると、imshow()を使っていることが分かった。前処理を含み参考にしてgwtspecgramを実装する。
[[→matplotlib.specgram>https://gist.github.com/peace098beat/9812bd04612a3f656abc]]
#ref(figure_specgram.png,,noimg,30%)
#ref(figure_scarogram.png,,around,right,30%)
** タイトル title() [#b1ceeae7]
サンプルコードを見ていると、titleの表示方法が2種類見られる。
- Basic text commands
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('axes title')
-
fig = plt.figure()
ax = fig.gca()
plt.title('axes title')
違いを調べるために、plt.title()の中身を確認したところ、中では同じset_title()が呼ばれていた。matlab風にするためのラッピングかもしれない。
- plt.title()
def title(s, *args, **kwargs):
l = gca().set_title(s, *args, **kwargs)
draw_if_interactive()
return l