简体   繁体   English

使用Gadfly绘制多个数据文件

[英]Plotting multiple data files with Gadfly

I'm trying to plot different data files using Gadfly. 我正在尝试使用Gadfly绘制不同的数据文件。 I tried using a DataFrame, but with no result. 我尝试使用DataFrame,但没有结果。

I tried using the below code but it just plots the last data file. 我尝试使用下面的代码,但它只是绘制最后一个数据文件。 I don´t know how to plot all the data file in just one plot using Gadfly. 我不知道如何使用Gadfly在一张图中绘制所有数据文件。

data1 = CSV.read("DOC.CSV")
data2 = CSV.read("DODC.CSV")
data3 = CSV.read("DOTC.CSV")
data4 = CSV.read("DTC.CSV")
data5 = CSV.read("DTDC.CSV")
data6 = CSV.read("DTTC.CSV")
data = [data1,data2,data3,data4,data5,data6]

ddframe = DataFrame()

for i in 1:6
    ddframe[Symbol("Data"*string(i))]=DataFrame(x=data[i][!,1],y=data[i][!,2],label="Data "*string(i))
end

p = plot(ddframe,x="x",y="y",color="label",Geom.point,Geom.line,Guide.xlabel("Wavelength(nm)"),Guide.ylabel("Absorbance(UA)"),Guide.title("Absorbance Spectrum for
        Cianine dyes"))

I assume your data is like this. 我认为您的数据是这样的。

│ x     │ y     │
│───────┼───────┤
│ 1     │ 1     │
│ 2     │ 3     │
│ 3     │ 5     │
│ 4     │ 7     │
│ 5     │ 9     │

Therefore, the data is an array of dataframes. 因此, data是数据帧的数组。

More, I assume a dataframe can be represented as a line (wavelength vs absorbance). 另外,我假设一个数据帧可以表示为一条线(波长与吸光度)。
According to your code, you may combine every dataframe into a plot, so what you need is the layer() function. 根据您的代码,您可以将每个数据帧组合成一个图,因此您需要的是layer()函数。

plot(
     layer(data[1],
           x=:x,
           y=:y,
           Geom.point,
           Geom.line,
           Theme(default_color="red")),

     layer(data[2],
           x=:x,
           y=:y,
           Geom.point,
           Geom.line,
           Theme(default_color="blue"))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM