当前位置:网站首页>Matplotlib drawing core principles explain (more detailed)
Matplotlib drawing core principles explain (more detailed)
2022-08-03 00:38:00 【51CTO】
1、核心原理讲解

使用matplotlibThe principle of drawing,主要就是理解figure(画布)、axes(坐标系)、axis(坐标轴)三者之间的关系.

Zhang SAN's sketchpad

matplotlib绘图

2、matplotlib库的安装与导入
1)安装
2)导入相关库
Now you don't need to pay attention to what is the exact meaning of the following code,There is a subjective impression can.I will be in a future article,Introduce you don't know which parameters one by one to you.
结果如下:

3、创建figure(画布)的两种方式
1)Draw a simple line chart
结果如下:

结果分析:
在前面的叙述中,我们已经说过,想要使用matplotlib绘图,Must first create afigure(画布)对象,然后还要有axes(坐标系).But watch the code,我们并没有创建figure对象,So how can draw?
对于上述疑问,Then we will be creatingfigure(画布)的两种方式.
2)创建figure(画布)的两种方式
- 隐式创建
- 显示创建
① 隐式创建figure对象
当第一次执行plt.xxx()The drawing code,系统会去判断是否已经有了figure对象,如果没有,系统会自动创建一个figure对象,并且在这个figure之上,自动创建一个axes坐标系(注意:默认创建一个figure对象,一个axes坐标系).
也就是说,如果我们不设置figure对象,那么一个figure对象上,只能有一个axes坐标系,That we can only draw a shape.
② 隐式创建figureThe problems existing in the object
优势:If we can only draw a small graphics,那么直接使用plt.xxx()的方式,会自动帮我们创建一个figure对象和一个axes坐标系,This graphics eventually is drawn in thisaxesCoordinate system of.
劣势:If we want to be in afigure对象上,绘制多个图形,So we must get eachaxes对象,And then call each positionaxes对象,Can be in the position of each corresponding coordinate system on,进行绘图,如下图所示.注意:如果figureObject is created by default,So we simply can't getaxes对象.因此,We need to show to createfigure对象.

③ 显示创建figure对象:Future articles will be detailed layout Settings
如图所示:

举例说明:
结果如下:

4、The complete drawing steps
① 导库
② 创建figure画布对象
③ 根据figureObject to layout Settings
④ 获取对应位置的axes坐标系对象
⑤ 调用axes对象,进行对应位置的图形绘制
⑥ 显示图形
5、绘图技巧(细节设置)
通过对matplotlibThe principle of drawing,有所了解之后,We need to learn is commonmatplotlib绘图技巧,Common drawing techniques shown above,These drawing skills can be a good help us draw more beautiful、More intuitive graphics.下一节,I will tellmatplotlib绘图技巧(千万不要错过).
边栏推荐
猜你喜欢
随机推荐
双轴晶体中锥形折射的建模与应用
【Unity】Unity开发进阶(六)UnityEvent使用与源码解析
若依如何实现添加水印功能
Teach you how to kill if else
面试官居然问我:删库后,除了跑路还能干什么?
牛客刷题:手动实现数组filter方法
若依集成minio实现分布式文件存储
YARN资源调度系统介绍
从月薪10k到30k的必走之路:自动化测试
UDP (User Datagram Protocol)
JumpServer open source bastion machine completes Loongson architecture compatibility certification
最近火爆朋友圈的“广告电商”,核心商业模式是什么,广告收入真实靠谱吗?
抽象工厂模式
golang刷leetcode:道路的最大总重要性
go rand 包
同样月薪6K,为什么同事跳槽月薪翻倍,而你只涨了1000?
JS 包装类 Math对象 round max() min() random
go 序列化与反序列化
golang刷letcode:公平分发饼干
go exec 包









