matplotlib.pyplot モジュール

matplotlib.pyplot モジュール

[APIドキュメント]

関数

axis

@ [APIドキュメント]

axis(*args, emit=True, **kwargs)

  • xmin, xmax, ymin, ymax = axis()
  • xmin, xmax, ymin, ymax = axis([xmin, xmax, ymin, ymax])
  • xmin, xmax, ymin, ymax = axis(option)
  • xmin, xmax, ymin, ymax = axis(**kwargs)
  • 引数
    • *args
      • [xmin, xmax, ymin, ymax] : X軸・Y軸のそれぞれ最小値・最大値 <list(float)>
      • option : 軸に関するオプションを指定する <str / bool>
        • ‘on’ / True : 軸とそのラベルを表示する
        • ‘off’ / False : 軸とそのラベルを表示する
        • ‘equal’
        • ‘scaled’
        • ‘tight’
        • ‘auto’
        • ‘normal’
        • ‘image’
        • ‘square’
    • emit
    • **kwargs
  • 戻り値
    • xmin : X軸の最小値 <float>
    • xmax : X軸の最大値 <float>
    • ymin : Y軸の最小値 <float>
    • ymax : Y軸の最大値 <float>

軸に関する情報を取得したり、設定したりします。

bar

@ [APIドキュメント]

bar(x, height, width=0.8, bottom=None, *, align=’center’, data=None, **kwargs)

boxplot

@ [APIドキュメント]

boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None, widths=None, patch_artist=None, bootstrap=None, usermedians=None, conf_intervals=None, meanline=None, showmeans=None, showcaps=None, showbox=None, showfliers=None, boxprops=None, labels=None, flierprops=None, medianprops=None, meanprops=None, capprops=None, whiskerprops=None, manage_ticks=True, autorange=False, zorder=None, *, data=None)

figure

@ [APIドキュメント]

figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=, clear=False, **kwargs)

  • 引数
  • 戻り値
    • figure : 作成されたFigureオブジェクト <Figure>

新規のFigureオブジェクトを作成します。

imread

@ [APIドキュメント]

imread(fname, format=None)

  • 引数
    • fname : 読み込む画像のファイル名/URL、もしくはfile-likeオブジェクト <str / file-like>
    • format : 画像のファイル形式(指定されない場合はfname引数から推測されます) <str>
  • 戻り値
    • imagedata : 読み込まれた画像データ <ndarray>
      • グレースケールの場合は、形状は(M, N)
      • RGB画像の場合は、形状は(M, N, 3)
      • RGBA画像の場合は、形状は(M, N, 4)

imsave

@ [APIドキュメント]

imsave(fname, arr, **kwargs)

imshow

@ [APIドキュメント]

imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=, filternorm=1, filterrad=4.0, imlim=, resample=None, url=None, *, data=None, **kwargs)

  • 引数
    • X : 画像データ <array-like / PIL image>
    • cmap : X引数がグレースケール画像で与えられた場合に、画素値に対応する色のマッピングを定義します <str / Colormap>
      • 組み込みのカラーマップ名、もしくはそのオブジェクトで指定します。
      • 組み込みカラーマップはmatplotlib.cmモジュールのグローバル変数として定義されています。
      • X引数にRGB画像やRGBA画像が与えられた場合は、cmapは無視されます。
    • norm : <Normalize>
    • aspect : <{‘equal’ / ‘auto’} / float>
    • interpolation : <str>
    • alpha : <scalar / array-like>
    • vmin : <scalar>
    • vmax : <scalar>
    • origin : <{‘upper’ / ‘lower’}>
    • extent : <scalars>
    • filternorm : <bool>
    • filterrad : <float>
    • resample : <bool>
    • url : <str>
  • 戻り値
    • image : <AxesImage>

画像を表示します。

legend

@ [APIドキュメント]

legend(*args, **kwargs)

  • legend()
  • legend(labels)
  • legend(handles, labels)
  • 引数
    • labels : <List(Artist)>
    • handles : <List(str)>
  • 戻り値
    • legend : 設定された凡例を表すオブジェクト <Legend>

matshow

@ [APIドキュメント]

matshow(A, fignum=None, **kwargs)

plot

@ [APIドキュメント]

plot(*args, scalex=True, scaley=True, data=None, **kwargs)

  • plot([x], y, [fmt], *, data=None, **kwargs)
  • plot([x], y, [fmt], [x2], y2, [fmt2], …, **kwargs)
  • 引数
    • *args
      • x : X座標の値、もしくはその配列 <array-like / scalar>
      • y : Y座標の値、もしくはその配列 <array-like / scalar>
      • fmt : プロットの形状を表すフォーマット文字列 <str>
        • フォーマット文字列は ‘[marker][line][color]’ の3つの部分から成る
    • scalex : X軸の描画範囲を与えられたデータに従って自動で決めるかどうか <bool>
    • scaley : Y軸の描画範囲を与えられたデータに従って自動で決めるかどうか <bool>
    • data :
    • **kwarg : Line2Dクラスのプロパティを指定できます
  • 戻り値
    • lines : 描画されたグラフを表すLine2Dオブジェクトのリスト <list(Line2D)>

折れ線グラフをアクティブな描画領域(Figureオブジェクト)に描画します。

→ 詳細はAxesオブジェクトのplotメソッドをご覧ください

savefig

@ [APIドキュメント]

savefig(fname, dpi=None, facecolor=’w’, edgecolor=’w’, orientation=’portrait’, papertype=None, format=None, transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None, metadata=None)

現在のグラフを保存します。

scatter

@ [APIドキュメント]

scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, *, data=None, **kwargs)

  • 引数
    • x : <array-like>
    • y : <array-like>
    • s : <scalar / array-like>
    • c : <color / sequence / sequence(color)>
    • marker : <MarkerStyle>
    • cmap : <Colormap>
    • norm : <Normalize>
    • vmin : <scalar>
    • vmax : <scalar>
    • alpha : <scalar>
    • linewidths : <scalar / array-like>
    • edgecolors : <color / sequence(color)>
  • 戻り値
    • paths : <PathCollection>

XとYの値から、様々なマーカーサイズ・色などから成る散布図を作成します。

show

@ [APIドキュメント]

show(*args, **kw)

  • 引数 : なし
  • 戻り値 : なし

すべてのFigureオブジェクトを表示し、それが閉じられるまでそれ以降のコードの実行を止めます。

subplots

@ [APIドキュメント]

subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw)

  • 引数
    • nrows : 作成する行数 <int>
    • ncols : 作成する列数 <int>
    • sharex : X軸を共有するかどうか <bool / {‘none’, ‘all’, ‘row’, ‘col’}>
      • False / ‘none’ -> 軸を共有しない
      • True / ‘all’ -> すべての軸を共有する
      • ‘row’ -> 各行の軸を共有する
      • ‘col’ -> 各列の軸を共有する
    • sharey : Y軸を共有するかどうか <bool / {‘none’, ‘all’, ‘row’, ‘col’}>
      • False / ‘none’ -> 軸を共有しない
      • True / ‘all’ -> すべての軸を共有する
      • ‘row’ -> 各行の軸を共有する
      • ‘col’ -> 各列の軸を共有する
    • squeeze
    • subplot_kw
    • gridspec_kw
  • 戻り値
    • fig : 作成されたFigureオブジェクト <Figure>
    • ax : 作成されたAxesオブジェクト(複数の場合は二次元リスト) <list(Axes)>

text

@ [APIドキュメント]

text(x, y, s, fontdict=None, **kwargs)

  • 引数
    • x : テキストの左端を示すX軸の値 <scalar>
    • y : テキストのベースラインを示すY軸の値 <scalar>
    • s : 描画するテキスト <str>
    • fontdict : Textクラスのプロパティを辞書としてまとめたフォントのスタイル <dict>
    • **kwargs : Textクラスのプロパティでフォントを指定する
  • 戻り値
    • text : 生成されたテキストのインスタンス <Text>

tight_layout

@ [APIドキュメント]

tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None)

  • 引数
  • 戻り値 : なし

自動でサブプロットの余白を調整して、重なりが出ないようにします。

title

@ [APIドキュメント]

title(label, fontdict=None, loc=None, pad=None, **kwargs)

  • 引数
    • label : タイトルに設定する文字列 <str>
    • fontdict : Textクラスのプロパティを辞書としてまとめたフォントのスタイル <dict>
    • loc : タイトルラベルを表示する位置 <{‘center’, ‘left’, ‘right’}>
    • pad : グラフエリアから文字列までの距離 <float>
    • **kwargs : Textクラスのプロパティを指定できます
  • 戻り値
    • text : 設定された文字列 <Text>

xlabel

@ [APIドキュメント]

xlabel(xlabel, fontdict=None, labelpad=None, **kwargs)

  • 引数
    • xlabel : X軸のラベルに設定する文字列 <str>
    • fontdict : Textクラスのプロパティを辞書としてまとめたフォントのスタイル <dict>
    • labelpad : グラフエリアから文字列までの距離 <scalar>
    • **kwargs : Textクラスのプロパティを指定できます
  • 戻り値
    • return : 設定された文字列 <Text>

X軸のラベルに指定した文字列を設定します。なお、デフォルトでは日本語の文字列を表示することはできません。

xticks

@ [APIドキュメント]

xticks(ticks=None, labels=None, **kwargs)

  • 引数
    • ticks : 目盛ラベルを配置する位置のリスト <array-like>
      • 空白のリストが指定された場合は、今の目盛をすべて削除します
    • labels : 目盛ラベルのリスト
    • **kwargs : Textクラスのプロパティを指定できます
  • 戻り値
    • locs : X軸の目盛の位置のリスト <List(float)>
    • labels : X軸の目盛ラベルのリスト <List(Text)>

ylabel

@ [APIドキュメント]

ylabel(ylabel, fontdict=None, labelpad=None, **kwargs)

  • 引数
    • ylabel : Y軸のラベルに設定する文字列 <str>
    • fontdict : Textクラスのプロパティを辞書としてまとめたフォントのスタイル <dict>
    • labelpad : グラフエリアから文字列までの距離 <scalar>
    • **kwargs : Textクラスのプロパティを指定できます。
  • 戻り値
    • return : 設定された文字列 <Text>

Y軸のラベルに指定した文字列を設定します。なお、デフォルトでは日本語の文字列を表示することはできません。

yticks

@ [APIドキュメント]

yticks(ticks=None, labels=None, **kwargs)

  • 引数
    • ticks : 目盛ラベルを配置する位置のリスト <array-like>
      • 空白のリストが指定された場合は、今の目盛をすべて削除します
    • labels : 目盛ラベルのリスト
    • **kwargs : Textクラスのプロパティを指定できます
  • 戻り値
    • locs : Y軸の目盛の位置のリスト <List(float)>
    • labels : Y軸の目盛ラベルのリスト <List(Text)>