2016-11-22 4 views
1

matplotlibのの凡例のエラーバンドのための領域は、次のように合併プラス:ライン網掛け、私は <a href="https://i.stack.imgur.com/TyRRj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TyRRj.png" alt="graph with uncertainty band"></a></p> <p>ではなく破線と黄色の領域と同様の伝説を持っていると思い

enter image description here

+0

これまでに試したことでいくつかのコードを提供すると効果的です –

答えて

2

あなたが望むことをするには、legendを1つのアイテムに2つのライン/パッチを組み合わせて呼び出す必要があります。この図で

# Import libraries 
import numpy as np 
import matplotlib.pyplot as plt 

# Create some fake data 
xvalue = np.linspace(1,100,100) 
pop_mean = xvalue 
walker_pos = pop_mean + 10*np.random.randn(100) 

# Do the plot 
fig, ax = plt.subplots() 

# Save the output of 'plot', as we need it later 
lwalker, = ax.plot(xvalue, walker_pos, 'b-') 

# Save output of 'fill_between' (note there's no comma here) 
lsigma = ax.fill_between(xvalue, pop_mean+10, pop_mean-10, color='yellow', alpha=0.5) 

# Save the output of 'plot', as we need it later 
lmean, = ax.plot(xvalue, pop_mean, 'k--') 

# Create the legend, combining the yellow rectangle for the 
# uncertainty and the 'mean line' as a single item 
ax.legend([lwalker, (lsigma, lmean)], ["Walker position", "Mean + 1sigma range"], loc=2) 

fig.savefig("legend_example.png") 
plt.show() 

このコードの結果:legend_example.png

あなたは何従うことLegend guideを見てみることができます

実際にこれを行う方法を参照するには、ここでは簡単な実施例でありますあなたが欲しいものに伝説を適応させることができます。

関連する問題

 関連する問題