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



前,我确实从目录中移动了一些文件并复制到一个新目录中, 复制时,我确实重命名了每个。为此,我使用了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 
...

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

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)
...

提前致谢:)

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

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

请注意,当您使用 StatPlots 绘图时,您不需要using Plotsusing PlotlyJS,我也不明白为什么您需要DistributionsLaTeXStrings

最新更新