传说不会显示

时间:2016-09-27 05:43:53

标签: python-2.7 matplotlib data-visualization legend

黑色和红色图表的图例未显示

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()

1 个答案:

答案 0 :(得分:0)

String.matches

使用plt.legend()

enter image description here