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 でリストを結合する方法

2つのリストを結合して、「リストのリストを作りたい場合」と、「1つの長いリストを作りたい」場合がある。 それぞれ、次のようにする。 例 # リスト2つを用意 l_1 = [1,2,3] l_2 …

no image

python3 で、フォルダがなければ作成するプログラム

os.mkdir() 関数を使う。 すでにフォルダが存在している場合は、エラーを表示する。 例 import os folder_name = ‘./python_create_folder’ try …

no image

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

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

matplotlib のグラフ作成と gnuplot との対応 比較

起動方法 gnuplot コマンドで $ gnuplot とすれば起動できる。 初期設定ファイルは gnuplotrc にある。 gnuplotrc の場所の見つけ方(macの場合) https:// …

no image

python3 で csv ファイルを読み込んで、最初の数行を表示する方法

以下の例では、空の配列 data を用意しておき、最初の3行を読み込んでおく。 例 import csv with open(‘data.csv’,’r’) as csv_file: csv_read …