Reputation: 33
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
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.
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 :)
Upvotes: 0
Views: 195
Reputation: 8044
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
.
Upvotes: 1