朱莉娅,绘制直方图或任何来自循环中的一系列文件(列表)

时间:2022-02-15 14:58:03

Time ago, I did move some files from a directory and copied to a new one, while copying I did rename each one. For doing so , I used bash. Something like this

前一段时间,我确实从一个目录中移动了一些文件并复制到一个新文件,而复制时我确实重命名了每个文件。为此,我使用了bash。像这样的东西

for i in 8 12 16 20 ; do;
   for j in 0.00 0.01 ; do ;    
    cp  tera.dat new/tera$i$j.dat 
...

Into each tera$i$j.dat, there is numeric data in 2 columns. I would like to plot the data as a histogram, and save each image (if possible in a loop) for each file tera$i$j.dat . But unfortunately, I do not have much idea how to do this. I managed to load the data in several tables using de = readtable.(filter(r"tera", readdir()),separator =' ', header= false,;. But I can not create a plot for each data :( So far I managed to read the file, and create a histogram plot for 1 file per time, how do I do it in a loop ? This is the code I am using.

在每个tera $ i $ j.dat中,有2列数字数据。我想将数据绘制为直方图,并为每个文件tera $ i $ j.dat保存每个图像(如果可能的话,在循环中)。但不幸的是,我不知道该怎么做。我设法使用de = readtable将数据加载到几个表中。(filter(r“tera”,readdir()),separator ='',header = false ,;。但是我不能为每个数据创建一个图:(到目前为止,我设法读取文件,并为每次创建一个文件的直方图,我如何在循环中执行?这是我正在使用的代码。

using Plots StatPlots,  Distributions, DataFrames, PlotlyJS, LaTeXStrings;
theme(:sand);
chp = pwd(); 
pe = readtable("tera120.00.dat",separator =' ', header= false)
gr()
histogram(pe[2], nbins=1000)
...

Thanks in advance :)

提前致谢 :)

1 个解决方案

#1


1  

Untested, but it should be something like this:

未经测试,但它应该是这样的:

using StatPlots, DataFrames
theme(:sand)
gr()
for i in [8, 12, 16, 20], j in [0, 0.01]
    fn = @sprintf "tera%02d.%02d" i j
    pe = readtable(fn*".dat", separator =' ', header = false)
    p = histogram(pe[2], bins = 1000);
    savefig(p, fn*".png")
end

Note that when you plot with StatPlots, you don't need using Plots or using PlotlyJS, I also don't see why you need Distributions or LaTeXStrings.

请注意,当您使用StatPlots绘图时,您不需要使用Plots或使用PlotlyJS,我也不明白为什么需要分布或LaTeXStrings。

#1


1  

Untested, but it should be something like this:

未经测试,但它应该是这样的:

using StatPlots, DataFrames
theme(:sand)
gr()
for i in [8, 12, 16, 20], j in [0, 0.01]
    fn = @sprintf "tera%02d.%02d" i j
    pe = readtable(fn*".dat", separator =' ', header = false)
    p = histogram(pe[2], bins = 1000);
    savefig(p, fn*".png")
end

Note that when you plot with StatPlots, you don't need using Plots or using PlotlyJS, I also don't see why you need Distributions or LaTeXStrings.

请注意,当您使用StatPlots绘图时,您不需要使用Plots或使用PlotlyJS,我也不明白为什么需要分布或LaTeXStrings。