如何用numpy绘制文件? [英] How to plot files with numpy?

查看:99
本文介绍了如何用numpy绘制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.dat文件,其中包含两列数字,因此看起来像这样:

I have a .dat file that contains two columns of numbers so it looks something like this:

111    112
110.9  109
103    103

以此类推.

我想将两列相互绘制.我以前从未处理过.dat文件,所以我不确定从哪里开始.

I want to plot the two columns against one another. I have never dealt with a .dat file before so I am not sure where to start.

到目前为止,我发现numpy可以用来调用.

So far I figured out that numpy has something I can use to call.

data = numpy.loadtxt('data.DAT')

但是我不确定从这儿去哪里.有什么想法吗?

but I'm not sure where to go from here. Any ideas?

推荐答案

Numpy本身不支持绘图.通常,您可以使用 matplotlib 绘制numpy数组.

Numpy doesn't support plotting by itself. You usually would use matplotlib for plotting numpy arrays.

如果您只想查看文件",我认为最简单的方法是使用

If you just want to "look into the file", I think the easiest way would be to use plotfile.

import matplotlib.pyplot as plt 

plt.plotfile('data.dat', delimiter=' ', cols=(0, 1), 
             names=('col1', 'col2'), marker='o')
plt.show()

您可以在ipython中像gnuplot一样使用此功能:

You can use this function almost like gnuplot from within ipython:

$ ipython --pylab
...
...
In [1]: plt.plotfile('data.dat', delimiter=' ', cols=(0, 1), 
...                  names=('col1', 'col2'), marker='o')

或将其放在shell脚本中,并将参数传递给它,以直接从您的shell中使用它

or put it in a shell script and pass the arguments to it to use it directly from your shell

这篇关于如何用numpy绘制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆