少ないほど効果的
少ないほど魅力的
少ない少ないほど影響力がある
これは、Matplotlibアーキテクチャに関するメモです。主に、クラスのコンテンツと自分で見つけた情報があり、英語のフォルダにあり、参照として使用できます。
Matplotlibアーキテクチャの概要
Matplotlibアーキテクチャ
Matplotlibアーキテクチャは、スタックとして表示できる3つのレイヤーに分割されています。別のレイヤーの上の各レイヤーは、その下のレイヤーと通信する方法を知っていますが、下のレイヤーはその上のレイヤーを知りません。下から上への3つのレイヤーは、バックエンド、アーティスト、スクリプトレイヤーです。
バックエンドレイヤー(FigureCanvas、レンダラー、イベント)
3つの組み込み抽象インターフェースクラスがあります。
- FigureCanvas:matplotlib.backened_bases.FigureCnvas
- 図が描かれている領域を含みます
- 画用紙など
- レンダラー:matplotlib.backened_bases.Renderer
- FigureCanvasを利用する方法を知っています
- 例:ブラシ
- イベント:matplotlib.backend_bases.Event
- キーボードストロークやマウスクリックなどのユーザー入力を処理します
アーティストレイヤー(アーティスト)
- 1つの主要なオブジェクトで構成されています-アーティスト:
- レンダラーを使用してキャンバスに描画する方法を知っています。
- matplotlib Figureに表示されるものはすべて、Artistのインスタンスです。
- タイトル、線、目盛りラベル、画像はすべて、個々のアーティストインスタンスに対応しています。
- 2種類のArtistオブジェクト:
- プリミティブ:Line2D、Rectangle、Circle、およびText
- コンポジット:軸、目盛り、軸、および図
- 各アーティストには、原始的なアーティストだけでなく、他の複合アーティストも含まれる場合があります。
アーティストと一緒に描いた例〜
# Putting the Artist Layer to Use
# generate a histogram of some data using the Artist layer
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas # import FigureCanvas
from matplotlib.figure import Figure # import Figure artist
fig = Figure()
canvas = FigureCanvas(fig)
# create 10000 random numbers using numpy
import numpy as np
x = np.random.randn(10000)
ax = fig.add_subplot(111) # create an axes artist
ax.hist(x, 100) # generate a histgram of the 10000 numbers
# add a little to the figure and save it
ax.set_title('Normal distribution with $\mu=0, \sigma=1$')
fig.savefig('matplotlib_histogram.png')
スクリプトレイヤー(pyplot)
- 毎日の使用、より簡潔
- 主にpyplotで構成されています。これは、Artistレイヤーよりも軽量なスクリプトインターフェイスです。
- pyplotインターフェースを使用して、10000個のランダム値の同じヒストグラムを生成する方法を見てみましょう。
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(10000)
plt.hist(x, 100)
plt.title(r'Normal distribution with $\mu=0, \sigma=1$')
plt.savefig('matplotlib_histogram.png')
plt.show()