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

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

no image

matplotlib で、グラフ内に注釈ラベルをつける方法

annotate を使う 例 import numpy as np import matplotlib.pyplot as plt ax = plt.figure().add_subplot() th …

no image

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

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

no image

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

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

no image

matplotlib で csv ファイルからデータを読み込んでグラフを表示する方法

np loadtext で csv ファイルを読み込む。 pyplot.bar で棒グラフを表示する。 例 import numpy as np from matplotlib import pypl …