1. 生成数据
1.1 matplotlib安装
1.1.1 matplotlib安装
win+R打开运行窗口,输入cmd回车打开cmd命令窗口,输入python -m pip install --user matplotlib,如下图所示。
1.1.2 测试matplotlib
在cmd命令行输入python启动python终端会话,输入import matplotlib,如下图显示则matplotlib安装成功。
1.2 绘制简单折线图
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
input_values = [1,2,3,4,5]
squares = [1,4,9,16,25]
plt.plot(input_values,squares,linewidth=5)
#设置图标标题,并给坐标轴加上标签
plt.title("Square Numbers",fontsize=10)
plt.xlabel("Value",fontsize=10)
plt.ylabel("Square of Value",fontsize=10)
#设置刻度标记的大小
plt.tick_params(axis='both',labelsize=14)
plt.show()