python中引用matplotlib画图的几个常用命令及基本步骤
2017-10-20 09:16
956 查看
①引包:import matplotlib.pyplot as plt;
②创建画布:fig = plt.figure();
③添加分区:ax = fig.add_subplot(311) #三个数字分别代表行、列及本图所处位置;
④ax..axis([-5,5,0,1]) #设置x轴最小、最大值,y轴最小、最大值;
⑤ax.scatter(xcord1,ycord1, s=30, c='red', marker='s') #用于画散点图;
⑥ax.plot(x, y) #用于画线图;
⑦plt.title(“this is a title”) #图形添加标题;
⑧plt.xlabel('x')、plt.ylabel('y') #分别对坐标轴添加标题
⑨plt.show() #显示图形;
完毕!!!
plot作图的几种特殊情况:
①、单列表,例如:n = [1,2,5,6]
ax.plot(n)作出的图以列表元素的索引为x轴,索引对应值为y轴显示,如下图:
②二维列表,例如m = [ [2,3], [5,5], [7,6] ]
ax.plot(m)作出的图以第一维列表元素的索引为x轴,第二维列表的第一个值和第二个值组成两个单列表(分别为:[2,5,7]和[3,5,6]),如下图:
③、矩阵作图与第②种情况类似。
②创建画布:fig = plt.figure();
③添加分区:ax = fig.add_subplot(311) #三个数字分别代表行、列及本图所处位置;
④ax..axis([-5,5,0,1]) #设置x轴最小、最大值,y轴最小、最大值;
⑤ax.scatter(xcord1,ycord1, s=30, c='red', marker='s') #用于画散点图;
⑥ax.plot(x, y) #用于画线图;
⑦plt.title(“this is a title”) #图形添加标题;
⑧plt.xlabel('x')、plt.ylabel('y') #分别对坐标轴添加标题
⑨plt.show() #显示图形;
完毕!!!
plot作图的几种特殊情况:
①、单列表,例如:n = [1,2,5,6]
ax.plot(n)作出的图以列表元素的索引为x轴,索引对应值为y轴显示,如下图:
②二维列表,例如m = [ [2,3], [5,5], [7,6] ]
ax.plot(m)作出的图以第一维列表元素的索引为x轴,第二维列表的第一个值和第二个值组成两个单列表(分别为:[2,5,7]和[3,5,6]),如下图:
③、矩阵作图与第②种情况类似。
相关文章推荐
- Python数据分析之可视化一matplotlib(常用方法)
- Python:matplotlib画图----如何控制画图范围,如何画两条曲线间的阴影,如何控制Y轴现实范围
- python3使用matplotlib画图支持中文
- Python之Matplotlib画图方法
- Python数据可视化图像库MatPlotLib基本图像操作
- python中matplotlib包的基本使用
- 【Python】Matplotlib画图(二)——根据函数公式画图
- 【Python】Matplotlib画图(八)——条形图
- python matplotlib画图 画多个子图
- python的matplotlib画图时无法显示中文的解决方法
- python 中matplotlib 画图导入到word中如何保证分辨率
- Python中常用模块re,matplotlib,pandas,sys,mysql
- Matplotlib常用画图代码2
- opensuse42下python matplotlib画图不显示
- python中scatter()函数用法,matplotlib画图
- Mac使用 matplotlib 画图 => RuntimeError: Python is not installed as a framework
- python matplotlib 入门系列一:基本用法
- Python实战小程序利用matplotlib模块画图代码分享
- python 使用matplotlib画图
- Python 使用matplotlib画图添加标注、及移动坐标轴位置