散布図の2つの線の間を埋めることを試みています。これは散布図の平均値の周りの標準偏差を示すためです。fill_between 2つのx値の間だけを塗りつぶし、散布グラフ全体を塗りつぶすのではなく、matplotlib
import matplotlib.pyplot as plt
import numpy as np
y1 # is the first set of y-axis data
y2 # is the second set of y-axis data
y3 # is the third set of y-axis data
x # is the x-axis data set
ym1 = np.mean(y1)
ym2 = np.mean(y2)
ym3 = np.mean(y3)
# To set up the means of the three data series
sigma1 = np.std(y1)
sigma2 = np.std(y2)
sigma3 = np.std(y3)
# To set up the standard deviations
ysupper1 = ym1 + sigma1
ysupper2 = ym2 + sigma2
ysupper3 = ym3 + sigma3
yslower1 = ym1 - sigma1
yslower2 = ym2 - sigma2
yslower3 = ym3 - sigma3
# To set up the higher and lower limits to fill between
yma1 = np.array([ym1])
yma2 = np.array([ym2])
yma3 = np.array([ym3])
# To set up values to put into a plt.axhline
これらが設定された後、xに対してy1、y2、y3のグラフが作成されます。ここで問題は発生しません。しかし、これは常に作成するグラフのみx軸に沿った2つの点の間の充填を有する
plt.axhline(yma1, linestyle='--', color='b', alpha=0.7),
plt.axhline(yma2, linestyle='--', color='r', alpha=0.7),
plt.axhline(yma3, linestyle='--', color='c', alpha=0.7),
# To create the 'mean value' lines on the graph
plt.fill_between(x, ysupper1, yslower1, color='b', alpha=0.3),
plt.fill_between(x, ysupper2, yslower2, color='r', alpha=0.3),
plt.fill_between(x, ysupper3, yslower3, color='c', alpha=0.3),
# To fill in between the upper and lower limits of the standard deviation
:私はその後plt.axhline
年代とplt.fill_between
'Sを設定します。私は手動でplt.fill_between
のwhere
引数がNone
であると述べ、何も変更されていないことを期待しています。私はx軸に沿って見かけ上任意の点にこれらの点を埋めるだけなのはなぜですか?
編集:答えは、いつものように、それが原因で機能の動作方法を正確に理解するための失敗であったとして発見された参考のためにここで私は取得していますグラフの画像です。
'fill_between'は' plot'とほぼ同じであると考えてください。ただし、 'x'-dataを使って1行に2行しか書いてください。私はそこからあなたが独立して進歩することができると思います。 –
xの範囲はあなたのx軸の範囲ですか?私はあなたのグラフは、あなたのグラフの塗りつぶされた部分をカバーすると思います – heyu91
質問のコードは正しく動作するようですので、(いつものように)問題の[mcve]を提供する必要があります。 – ImportanceOfBeingErnest