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 で、すべて小文字かどうかを判定する方法

islower() 関数を使う。 例 print(‘abcde’.islower()) print(‘abcDe’.islower()) 結果 True False

no image

python3 でリストを結合する方法

2つのリストを結合して、「リストのリストを作りたい場合」と、「1つの長いリストを作りたい」場合がある。 それぞれ、次のようにする。 例 # リスト2つを用意 l_1 = [1,2,3] l_2 …

no image

matplotlib で、軸に垂直・平行な線を書く方法

axhline, axvline を使ってx,y軸に平行な線を描くことができる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot …

no image

python3 で文字列を入力させて受け取る方法

C言語で scanf のようなものを作るには、python では input() で実現できる。 例 print(‘xの値を入力してください’) x = input() print(‘xの値は ‘ + …

no image

python でファイルを1行おきに読み込む方法

readline を使って次のように書く。 例 ファイル:data.txt # id name age 1 佐藤太郎 10 2 鈴木花子 18 3 坂本明美 21 4 松村光子 24 5 小川奏子 1 …