matplotlib python3

matplotlib で、複数のグラフを簡単にプロットする方法

投稿日:

変数を並べて書くと、次のように自動的に順番を理解してグラフを表示してくれる。

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)

x = np.linspace(-3, 3, num=100, endpoint=True)
y1 = np.sin(x)
y2 = np.cos(x)

fig, ax = plt.subplots()
ax.plot(x,y1,'red',x,y2,'blue')
ax.legend(['sin','cos'])

plt.show()

結果

-matplotlib, python3
-,

執筆者:


comment

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

関連記事

no image

matplotlib で、2種類のデータをプロットする方法

下では、凡例(legend)を設定している。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = [ …

matplotlib のグラフ作成と gnuplot との対応 比較

起動方法 gnuplot コマンドで $ gnuplot とすれば起動できる。 初期設定ファイルは gnuplotrc にある。 gnuplotrc の場所の見つけ方(macの場合) https:// …

no image

matplotlib で折れ線グラフの下部に色をつけて塗りつぶす方法

pyplot の fill_between を使う。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = & …

no image

python3 で切り捨て割り算(除算)

python3 で整数の割り算をして、商(の整数部)を表示するには // 演算子を使う。余りが発生した場合、商は切り捨てた整数部となる。 例 n = 201 print(str(n//2)) 結果 1 …

no image

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

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