当前位置:网站首页>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使用与源码解析

软件测试笔试题1(附答案)

Sentinel vs Hystrix 限流对比,到底怎么选?

【TypeScript】深入学习TypeScript类(下)

Teach you how to kill if else

If the watermark according to how to realize the function

The only way to go from a monthly salary of 10k to 30k: automated testing

面试官居然问我:删库后,除了跑路还能干什么?
![[TypeScript] Deep Learning of TypeScript Classes (Part 1)](/img/47/34954f1e01b844816d74f3ac556f9b.png)
[TypeScript] Deep Learning of TypeScript Classes (Part 1)
随机推荐
【干货】分库分表最佳实践
面试了个985毕业的,回答“性能调优”题时表情令我毕生难忘
Command line startup FAQs and solutions
What is the core business model of the "advertising e-commerce" that has recently become popular in the circle of friends, and is the advertising revenue really reliable?
【Unity】Unity开发进阶(六)UnityEvent使用与源码解析
Interviewer: can you talk about optimistic locking and pessimistic locks
kubernetes pod podsecurityPolicies(PSP)
面试官:可以谈谈乐观锁和悲观锁吗
Redis是如何轻松实现系统秒杀的?
go 序列化与反序列化
一群搞社区的人
golang刷leetcode: 在每个树行中找最大值
How many ways do you know the singleton pattern?
字节内部技术图谱 惊艳级实用
Win10怎么开启自带的游戏录屏功能?
go exec 包
JS Date 时间戳 getTune data.parse 倒计时小程序
无线振弦采集仪远程修改参数的方式
树形结构构造示例代码
总结嵌入式C语言难点(2部分)