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

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

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

no image

python3 で、配列の配列をソートする

ラムダ式を使って、任意の要素についてソートすることができる。 例 arr = [[1,2,3],[2,1,2],[3,3,4],[4,4,1]] for i i …

no image

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

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

no image

python3 で集合(set)の和集合を作る

集合にモノを付け足して和集合を作るには、|= 演算子を使う。(python では、集合(set)を波かっこで囲んで表す。) 例 a = {‘東京’} b = {‘大阪’,’千葉’} c = a | b …

no image

python3 でコンソールからの入力をリストに格納する方法

入力を受け取るには、input() を使う。range(0,5) で、5個の文字列を順に受け取り、リストに入れてそれを表示する。 例 list1 = [] for i in range(0, …