2016-11-22 2 views

답변

2

원하는 것을하기 위해서, legend에 하나의 항목에 원하는 두 개의 라인/패치를 결합해야합니다. 이 그림에서

# 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 좀 걸릴 수 있습니다

실제로이 작업을 수행하는 방법을 보려면 여기를 간단한 작업 예입니다 당신이 원하는 것을 전설에 적용 할 수 있습니다.