matplotlib python3

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

投稿日:

pyplot の fill_between を使う。

from matplotlib import pyplot as plt

data_x = [25,26,27]
data_y = [19,41,50]
data_y2 = [40,20,17]
data_y3 = [18,25,37]

plt.plot(data_x,data_y, linestyle='solid', marker='o')
plt.fill_between(data_x,data_y, alpha=0.2)
plt.plot(data_x,data_y2, linestyle='dashed', marker='o')
plt.fill_between(data_x,data_y2, alpha=0.2)

plt.show()

結果

-matplotlib, python3
-,

執筆者:


comment

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

関連記事

no image

matplotlib で、矢印を描く方法

arrowprops のパラメータは次を参考にして設定できる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.FancyAr …

no image

python3 でランダムな整数の配列を作る方法

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

no image

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

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

no image

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

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

no image

matplotlib で、ヒストグラムを作成する方法

ヒストグラムを描くには、data_hist を使う。 ヒストグラムの縦棒の数は bins で指定する。 例 from matplotlib import pyplot as plt data_hist …