Python使用Numpy模块读取文件并绘制图片
作者:Iceberg_710815 时间:2022-03-11 07:11:58
代码如下
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = np.loadtxt('distance.txt',dtype = np.int)
print(data)
x = data[:,0] # 设置第1列数据为x轴数据。
y = np.log(data[:,1]) # 设置第2列为y轴数据,计算自然对数后赋值给y, 注意如果取以10为底的对数,则需要使用log10方法。
print(x[2])
print(y[2])
plt.figure(figsize= (6, 2.5)) # 设置图形宽高比
plt.plot(x, y, 'o')
# plt.ylabel('log(PGV)(微米/秒')
plt.plot(x[2],y[2],'o',color='red') # 用第3行数据突出显示数据,红线圆点。
plt.grid(ls = '--') # 设置网络线风格为虚线
plt.show()
结果
使用Numpy模块的loadtxt方法读取数据为数组,这种读取文件的方法比通常的open方式读取的文件,更容易操作。
来源:https://www.cnblogs.com/iceberg710815/p/12718301.html
标签:Python,Numpy,模块,读取,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python2.7版os.path.isdir中文路径返回false的解决方法
2021-02-03 09:56:42
python运用sklearn实现KNN分类算法
2022-12-04 03:53:19
![](https://img.aspxhome.com/file/2023/4/127604_0s.jpg)
用javascript结合Cookies记录浏览历史
2008-02-12 12:37:00
python 处理dataframe中的时间字段方法
2021-04-27 05:21:33
virtualenv实现多个版本Python共存
2021-11-27 00:50:44
![](https://img.aspxhome.com/file/2023/6/64706_0s.png)
深入分析在Python模块顶层运行的代码引起的一个Bug
2021-06-29 01:26:29
OpenCV 图像分割实现Kmean聚类的示例代码
2023-08-10 18:59:41
![](https://img.aspxhome.com/file/2023/3/64703_0s.jpg)
python实现CTC以及案例讲解
2023-04-18 22:04:13
![](https://img.aspxhome.com/file/2023/6/92176_0s.png)
Python利用Canny算法检测硬币边缘
2022-05-15 08:04:43
![](https://img.aspxhome.com/file/2023/5/131735_0s.png)
Python的Bottle框架中获取制定cookie的教程
2021-06-28 02:34:20
基于python if 判断选择结构的实例详解
2023-01-15 22:45:03
python使用PIL模块获取图片像素点的方法
2022-07-28 10:57:57
python中如何提高图像质量
2023-05-17 17:02:03
![](https://img.aspxhome.com/file/2023/4/86424_0s.jpg)
python关闭print输出信息详情
2023-06-21 17:21:09
Python采集某评论区内容的实现示例
2023-02-28 15:07:10
![](https://img.aspxhome.com/file/2023/7/75077_0s.png)
PHP手机号码归属地查询代码(API接口/mysql)
2023-10-26 04:35:44
Python matplotlib底层原理解析
2021-05-11 07:05:29
![](https://img.aspxhome.com/file/2023/1/93631_0s.png)
PyTorch中的CUDA的操作方法
2022-02-24 18:54:41
![](https://img.aspxhome.com/file/2023/2/77722_0s.png)
python实现分析apache和nginx日志文件并输出访客ip列表的方法
2022-07-08 00:33:16
HTML5本地存储初探(二)
2010-03-07 15:47:00
![](https://img.aspxhome.com/file/UploadPic/20103/7/20100131-rmki9pjq85xy9nbt436gkdfb7i-94s.png)