matplotlib绘制两点间连线的几种方法实现
作者:津津小可爱 时间:2021-07-27 09:02:24
为了找到matplotlib在两个点之间连线的方法真是费了好大功夫,本文主要介绍了 matplotlib绘制两点间连线的几种方法,具体如下
绘制方法 <1>
本文将通过最简单的模式拆解Matplotlib绘图的几个组成部分,将cover以下内容
1. Create a dataset
2. Create a canvas
3. Add data to canvas
4. Show the figure
import numpy as np
import matplotlib.pyplot as plt
# create a dataset
points = np.linspace(-5, 5, 256)
y1 = np.tanh(points) + 0.5
y2 = np.sin(points) - 0.2
# create a canvas
fig, axe = plt.subplots(figsize=(7, 3.5), dpi=300)
# add data to canvas
axe.plot(points, y1)
axe.plot(points, y2)
# show the figure
fig.savefig('output/to.png')
plt.close(fig)
绘制方法<2> 使用pyplot绘制图像
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 256)
y = np.sin(x)
plt.plot(x, y)
绘制方法<3> 使用axes类绘制图像
使用axes使用subplot()绘制单一图像,使用subplots(nrows,ncols
)绘制多个图形
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 256)
y = np.sin(x)
ax = plt.subplot()
ax.plot(x, y)
绘制方法<4> 使用figure类绘制图像
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 256)
y = np.sin(x)
fig = plt.figure(dpi=300)
ax = fig.add_subplot(111)
ax.plot(x, y)
fig.savefig('output/to.png')
plt.close(fig)
表示了图像的position。如果使用subplots,则有nrows
,ncols
, andindex
三个参数,其中idex从1开始,代表了左上角的图像
来源:https://blog.csdn.net/weixin_33918358/article/details/112486438
标签:matplotlib,连线
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python中while循环语句用法简单实例
2021-12-03 22:34:44
基于Python+Tkinter实现一个简易计算器
2021-06-23 00:40:29
![](https://img.aspxhome.com/file/2023/4/72244_0s.png)
Python基础之模块相关知识总结
2021-09-06 21:39:39
![](https://img.aspxhome.com/file/2023/1/70251_0s.png)
交互设计实用指南系列(3)—“有效性”之“适时帮助”
2009-12-25 14:29:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/04d4365a20d52fbefe705991235bec36-87s.gif)
关于设计品质保证(DQA)的几点想法
2007-11-16 16:55:00
python Kmeans算法原理深入解析
2022-03-01 07:26:55
![](https://img.aspxhome.com/file/2023/8/95548_0s.png)
解析SQL Server 2005 溢用之:合并列值
2009-01-23 14:08:00
ASP 递归调用 已知节点查找根节点的函数
2011-03-08 10:48:00
语义、标准和样式
2008-06-05 12:52:00
科讯CMS 5.0 模板标签清单列表
2008-12-04 13:18:00
Python下划线5种含义代码实例解析
2023-11-19 04:25:59
![](https://img.aspxhome.com/file/2023/3/87583_0s.jpg)
python中文件操作与异常的处理图文详解
2021-09-04 16:04:33
![](https://img.aspxhome.com/file/2023/2/78822_0s.jpg)
ajax标签导航实例详解教程
2008-02-01 10:54:00
![](https://img.aspxhome.com/file/UploadPic/up/2008020111434016.gif)
网页设计图标使用指南[译]
2009-03-11 21:13:00
![](https://img.aspxhome.com/file/UploadPic/20093/11/01-19s.jpg)
Python如何使用type()函数查看数据的类型
2022-05-30 17:49:31
![](https://img.aspxhome.com/file/2023/1/83861_0s.png)
django上传图片并生成缩略图方法示例
2022-08-12 01:45:53
Python爬取视频(其实是一篇福利)过程解析
2021-09-21 17:52:11
解决pytorch DataLoader num_workers出现的问题
2022-10-22 06:34:38
![](https://img.aspxhome.com/file/2023/2/97552_0s.jpg)
pydantic resolve解决嵌套数据结构生成痛点分析
2022-06-05 02:16:36
如何隐藏IP地址的最后一位
2011-04-04 16:38:00