python3

matplotlib で複数のグラフを並べて表示する方法

投稿日:

plot.subplots() でグラフの縦方向と横方向の数を指定する。

import numpy as np
from matplotlib import pyplot as plt

x1 = np.linspace(-5,5,100)
x2 = np.linspace(-1,1,100)

fig, axs = plt.subplots(2,2)
ax1 = axs[0,0]
ax2 = axs[0,1]
ax3 = axs[1,0]
ax4 = axs[1,1]
ax5 = axs[1,0]
ax6 = axs[1,1]

ax1.scatter(x1,np.sin(x), s=20, alpha=0.5)
ax2.scatter(x1,np.asin(x), s=20, alpha=0.5)
ax3.plot(x1,np.sin(x))
ax4.plot(x1,np.asin(x))
ax5.plot(x1,np.asin(x))
ax6.plot(x1,np.cos(x))

plt.show()

結果

-python3
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

python3 で辞書からタプルを作成する

辞書に対して、items() メソッドを使うと、タプルを作成することができる。 例 cities = {‘東京’:1000,’大阪’:700, ‘広島’:100} for a,b in cities. …

no image

python3 で、dictionary のキー一覧を取得する方法

dict.keys() でキーを取得することができる。 参考:dictionary の値一覧を取得するときは、dict.values() を使う。 例 print(dict.keys())

no image

python3 で、csv ファイルを読み込んで条件をみたす行の内容を表示する方法

csv.reader で読み込み、各行を読み込んで判定する。 例 import csv with open(‘data.csv’, ‘r’) as csv_file: reader = csv.rea …

no image

matplotlib でグラフ表示ウィンドウの画面上の位置を自由に設定する方法

matplotlib.use(‘TkAgg’) としておき、 get_current_fig_manager().window.wm_geometry(“+20+50”) として、(+20+50)のと …

no image

pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。

next() を使う。 例 my_arr = [‘春’,’夏’,’秋’,’冬’] my_iter = iter(my_arr) print(next(my_iter,’なし’)) print(next …