折线图
运行结果为:
代码如下:
import matplotlib.pyplot as plt
import matplotlib
'''
# =================简单折线图====================
x = ['2011', '2012', '2013', '2014', '2015', '2016', '2017']
y = [58000, 60200, 63000, 71000, 84000, 90500, 107000]
plt.plot(x, y)
plt.show() # 打开matplotlib查看器 '''
# =================复式折线图====================
x = ['2011', '2012', '2013', '2014', '2015', '2016', '2017']
y1 = [58000, 60200, 63000, 71000, 84000, 90500, 107000]
y2 = [52000, 54200, 51500, 58300, 56800, 59500, 62700]
y3 = [56000, 52200, 62000, 69000, 74000, 80500, 87000]
plt.plot(x, y1, color='r', linewidth='2',
linestyle='--', marker='^', label=u'水杯')
plt.plot(x, y2, color='b', linewidth='3',
linestyle='-.', marker='o', label=u'铅笔')
plt.plot(x, y3, color='y', linewidth='1',
linestyle=':', marker='+', label=u'手机')
plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置字体为SimHei显示中文
plt.rcParams['axes.unicode_minus'] = False
# chinese = matplotlib.font_manager.FontProperties(
# fname = 'C:\Windows\Fonts\simkai.ttf') # 楷体
# plt.legend(prop = chinese) # 图例中文显示
plt.legend()
plt.show()