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 でランダムな整数の配列を作る方法

random モジュールを使う。randint() の引数で、配列の最小値と最大値を指定できる。 例 import random random_arr = [random.randint(-2 …

no image

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

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

no image

python3 でグローバル変数とローカル変数で同じ名前の変数を使う

グローバル変数とローカル変数で同じ名前の変数を使うことができる。 例 x = 10 def myfunc(): x = 20 print(‘関数内: x = ‘+str(x)) myfunc() pr …

no image

matplotlib で、グラフのタイトルに上付き文字を入力する方法

数学記号などで、グラフのタイトルに上付きの文字を入力したい場合がある。 その場合は次のように書いて設定できる。 例 import numpy as np from matplotlib import …

no image

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

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