2016-09-27 6 views
0

Легенды черного и красного графика не получают отображенияЛегенды не получают отображения

years = [1950, 1960, 1970, 1980, 1990, 2000, 2010] 
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3] 
gdp_half = [150.1, 271.66, 538, 1431.3, 2989.8, 5144.9, 7479.1] 
plt.plot(years, gdp, color='k' ,linestyle = 'dashed', marker = 'o', label = 'one') 
[<matplotlib.lines.Line2D object at 0x04835C70>] 
plt.plot(years, gdp_half, color='r' ,linestyle = 'dashed', marker = 'o', label = 'two') 
[<matplotlib.lines.Line2D object at 0x04835550>] 
plt.show() 

ответ

0
import matplotlib.pyplot as plt 

years = [1950, 1960, 1970, 1980, 1990, 2000, 2010] 
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3] 
gdp_half = [150.1, 271.66, 538, 1431.3, 2989.8, 5144.9, 7479.1] 
plt.plot(years, gdp, color='k' ,linestyle = 'dashed', marker = 'o', label = 'one') 
plt.plot(years, gdp_half, color='r' ,linestyle = 'dashed', marker = 'o', label = 'two') 
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, 
      ncol=2, mode="expand", borderaxespad=0.) 
plt.show() 

Использование plt.legend()

enter image description here