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

python3 で整数の割り算、商と余りを求める方法

floor divisionを使う。 例 a = 15 // 7 b = 15 % 7 print(a) print(b) 結果 2 1

no image

python3 の辞書で、キー一覧を取り出して表示する方法

keys()メソッドでは、キー一覧を取得できる。values() では、値を取得できる。items() では、キーと値をタプルとして取得できる。 リストに変換すると、print() でコンソールに表示 …

no image

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

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

no image

python のプロンプトについて

UNIX で python を起動する ターミナルで $ python インタープリターのプロンプトは >>> となっている。 インタープリタを終了させるときは、Ctrl + D を押す。

no image

matplotlib のプロットスクリプト内で計算する方法

gnuplot の場合 gnuplot では、plot “data.txt” u 1:($2*2)などと書くと、 数値を加工(データ値を使った計算)を行った結果をグラフ化するこ …