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

python3 で、pathlib を使ってファイルの拡張子を取得する方法

pathlib モジュールの stem を使う。 この書き方は、python 3.4 以降で使えるようになった。 https://docs.python.org/3/library/pathlib.h …

no image

python3 で、すべて小文字かどうかを判定する方法

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

no image

python でファイルを1行おきに読み込む方法

readline を使って次のように書く。 例 ファイル:data.txt # id name age 1 佐藤太郎 10 2 鈴木花子 18 3 坂本明美 21 4 松村光子 24 5 小川奏子 1 …

no image

matplotlib で、グラフの点の見た目を変更する方法

「marker」で指定すればよい。 次のページを参考に、plotの「marker」を変更する。 https://matplotlib.org/stable/api/markers_api.html 例 …

no image

matplotlib で、縦横の線(グリッド)を描く方法

pyplot grid で縦横線(罫線のようなもの)を引くことができる。 例 from matplotlib import pyplot as plt data_x = [25,26,27] …