用.dat文件中的多行绘制Python中的几个图
我正在尝试从Python中的一个.dat文件绘制一组数据。
我想创建十个不同的地块,每个图上都有七个不同的行。 X值在1到100之间均匀间隔一百点。y值是列2:101的100点。应从第1列标记七行
。.DAT文件的格式如下:
第1列:我想要在图例中显示的值,有7个不同的值 第2-101列:我希望为这组七行之后的第1列中的每个值绘制的100个数据点
,然后有一个空白行,然后将模式重复总计十次(80行文件)。
任何帮助都非常欢迎,此文件格式比我习惯于处理的要复杂得多。
I am trying to plot a set of data from a .dat file in Python.
I want to create ten different plots, each with seven different lines displayed on them. X-values are a hundred points evenly spaced between 1 and 100. Y values are the 100 points from columns 2:101. Seven lines should be labeled from Column 1.
The format of the .dat file is as follows:
Column 1: The values that I want displayed in my legend, there are 7 different values
Columns 2-101: The set of 100 data points that I want plotted for each of the values in column 1
Following this set of seven rows, there is a blank line and then the pattern repeats for a total of ten times (80 lines in the file).
Any help would be very welcome, this file format is much more complex than I am used to dealing with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于X,您可以使用np.linspace(1,100,100)
您的dat.file。
np.loadtxt(“ input.dat”)
默认情况下,空白行将被忽略,现在您可以在数组中使用所有内容,您可以使用它想要的任何事情。
LOADTXT函数带有参数,例如USECOL和SKIPROWS,因此,如果您在第一列中的文件中有文本标签,则可以跳过这些标签。
( https://numpy.org/numpy.org/doc/doc/doc/stable/reference/reference/generate/generate/generated/generated/generated/generated/generated/generated /numpy.loadtxt.html )
用于绘图,您可以将课程
import matplotlib.pyplot用作PLT
,然后开始绘制带有LoadTXT的数组的不同列和行,您喜欢:)For X you can use np.linspace(1,100,100)
Your dat.file you can directly load as an array by utilizing
np.loadtxt("input.dat")
the blank lines will be ignored by default and now that you have everything in an array you can do anything you want with it.
The loadtxt function comes with parameters such as usecols and skiprows, so if you have text labels in your file in the first column or row you can skip over these.
(https://numpy.org/doc/stable/reference/generated/numpy.loadtxt.html)
for plotting you can use of course
import matplotlib.pyplot as plt
and then just start to plot the different columns and rows of the array you loaded with loadtxt to your liking :)