没有合适的资源?快使用搜索试试~ 我知道了~
首页Python读取txt某几列绘图的方法
资源详情
资源评论
资源推荐
Python读取读取txt某几列绘图的方法某几列绘图的方法
今天小编就为大家分享一篇Python读取txt某几列绘图的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看
看吧
晚上帮同学用Python脚本绘图,大概需求是读取一个txt文件的两列分别作为x和y的值,绘图即可,代码如下:
#coding:utf-8
import numpy as np
import matplotlib.pyplot as plt
import pylab
## 绘制该文件中的数据
## 需要引入pylab库,里面用到的函数和MATLAB里的非常类似
def plotData(x, y):
length = len(y)
pylab.figure(1)
pylab.plot(x, y, 'rx')
pylab.xlabel('x')
pylab.ylabel('y')
pylab.show()#让绘制的图像在屏幕上显示出来
x = []
y = []
x = [float(l.split()[3]) for l in open("07.txt")]
y = [float(l.split()[11]) for l in open("07.txt")]
plotData(x,y)
如果对跑的效果不满意可以用如果对跑的效果不满意可以用matplotlib重绘,代码如下:重绘,代码如下:
#coding:utf-8
import numpy as np
import matplotlib.pyplot as plt
import pylab
'''
## 绘制该文件中的数据
## 需要引入pylab库,里面用到的函数和MATLAB里的非常类似
def plotData(x, y):
length = len(y)
pylab.figure(1)
pylab.plot(x, y, 'rx')
pylab.xlabel('x')
pylab.ylabel('y')
#让绘制的图像在屏幕上显示出来
'''
x1 = [float(l.split()[3]) for l in open("New.txt")]
y1 = [float(l.split()[11]) for l in open("New.txt")]
x2 = [float(l.split()[3]) for l in open("Initial.txt")]
y2 = [float(l.split()[11]) for l in open("Initial.txt")]
plt.plot(x1, y1, 'b',linewidth=2.5, linestyle="-", label="cosine")
plt.plot(x2, y2, 'r',linewidth=2.5, linestyle="-", label="sine")
plt.legend(loc='upper left')
plt.show()
#plotData(x1,y1)
#plotData(x2,y2)
#pylab.show()
txt文件前几列示例如下:文件前几列示例如下:
9.999795e-01 5.025123e-04 -6.380358e-03 -4.596714e-03 -5.005160e-04 9.999998e-01 3.144878e-04 -2.001524e-03 6.380515e-03 -3.112871e-04 9.999796e-01 9.154274e-02
9.999096e-01 1.061516e-03 -1.340599e-02 -1.001116e-02 -1.058762e-03 9.999994e-01 2.126022e-04 -4.359704e-03 1.340621e-02 -1.983884e-04 9.999101e-01 1.857373e-01
9.997800e-01 1.386756e-03 -2.092925e-02 -1.753371e-02 -1.395506e-03 9.999989e-01 -4.034725e-04 -6.859665e-03 2.092867e-02 4.325913e-04 9.997809e-01 2.834672e-01
9.995454e-01 2.025309e-03 -3.008212e-02 -2.863192e-02 -2.080074e-03 9.999962e-01 -1.789331e-03 -6.726660e-03 3.007839e-02 1.851091e-03 9.995458e-01 3.873100e-01
9.991403e-01 2.230707e-03 -4.139680e-02 -4.273697e-02 -2.379114e-03 9.999909e-01 -3.536042e-03 -7.303015e-03 4.138854e-02 3.631490e-03 9.991365e-01 5.011396e-01
9.984892e-01 2.145631e-03 -5.490591e-02 -6.000009e-02 -2.394373e-03 9.999871e-01 -4.464951e-03 -8.065471e-03 5.489562e-02 4.589671e-03 9.984816e-01 6.279359e-01
9.974753e-01 2.223074e-03 -7.097932e-02 -8.275693e-02 -2.545053e-03 9.999869e-01 -4.446103e-03 -8.995000e-03 7.096851e-02 4.615524e-03 9.974679e-01 7.669396e-01
9.959798e-01 9.912399e-04 -8.957233e-02 -1.090497e-01 -1.397593e-03 9.999890e-01 -4.473982e-03 -1.033982e-02 8.956691e-02 4.581182e-03 9.959703e-01 9.191805e-01
9.939836e-01 -3.564687e-04 -1.095286e-01 -1.415335e-01 -1.406643e-04 9.999897e-01 -4.531084e-03 -1.195088e-02 1.095291e-01 4.519231e-03 9.939733e-01 1.081913e+00
9.912980e-01 -4.511767e-04 -1.316366e-01 -1.816057e-01 -1.745510e-04 9.999887e-01 -4.741873e-03 -1.604515e-02 1.316372e-01 4.723586e-03 9.912867e-01 1.251378e+00
weixin_38704011
- 粉丝: 3
- 资源: 947
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0