import matplotlib.pyplot as plt import numpy as np x1_list=[] # data1格納用のx_listを定義 z1_list=[] # data1格納用のz_listを定義 x2_list=[] # data2格納用のx_listを定義 z2_list=[] # data2格納用のz_listを定義 f1=open(filepath1) f2=open(filepath2) # プロットしたいデータが入っているファイルをr(読み込み) t(テキスト)モードで読み込む #data1読み込み for line in f1: data1 = line[:-1].split(' ') x1_list.append(float(data1[0])) z1_list.append(float(data1[1])) #data2読み込み for line in f2: data2 = line[:-1].split(' ') x2_list.append(float(data2[0])) z2_list.append(float(data2[1])) ## plt.xlabel('X') # x軸のラベル plt.ylabel('Z') # y軸のラベル plt.plot(x1_list, z1_list, color="White", alpha=0.8, linewidth=4.0, label="data1") plt.plot(x2_list, z2_list, color="White", alpha=0.8, linewidth=4.0, label="data2") plt.legend() plt.fill_between(np.append(x1_list, x2_list[::-1]), np.append(z1_list, z2_list[::-1]),where=z2_list>=z1_list, facecolor='green', interpolate=True)#二線の間の色を表す plt.fill_between(np.append(x1_list, x2_list[::-1]), np.append(z1_list, z2_list[::-1]),where=z2_list<=z1_list,facecolor='red', interpolate=True)#二線の間の色を表す # その他,描画用オプション plt.xticks(fontsize=10) plt.yticks(fontsize=10) plt.ylim([-21.62, -21.46]) plt.grid(True) #グラフの枠を作成 plt.savefig("cm.png") plt.show() fig = plt.figure()
plt.fill_betweenでgreenの部分しか表示されません。どうすれば意図したグラフが得られるでしょうか?
知っている方はぜひ教えていただけると助かります。
あなたの回答
tips
プレビュー