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 で、配列の配列をソートする

ラムダ式を使って、任意の要素についてソートすることができる。 例 arr = [[1,2,3],[2,1,2],[3,3,4],[4,4,1]] for i i …

no image

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

リストを iter に変えたあと、… next() を使う。 参考リンク https://www.programiz.com/python-programming/methods/buil …

no image

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

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

no image

python3 でファイルに内容を追記する方法

ファイルを開くとき、「a+」を指定することで、data.txt というファイルを書き込みモードで開く。(もしファイルが存在していなければ作成する。) 例 f = open(‘data.txt’, ‘a …

no image

python3 で、リストを pop したものの返り値

リストを pop すると、 pop された値が返される。 例 plant_1 = [’pumpkin’, ‘ginger’, ‘potato’] plant_2 = [] print( …