plotting subset of DataFrame in Julia

Viewed 421

I have data from a spectrometer who takes a measure every 5min or so, that I put in a CSV file.

The first column represents the time of the measure, the next two thousand columns represent the intensity of light at a given wavelength.

I'd like to get a 3D representation of how the spectrum evolves during the day, but so far I'm struggling to even plot a single spectrum of a given time.

I tried the following:

using Plots
using CSV
using DataFrames

gr()
Plots.GRBackend()

data = CSV.File("data/measures.csv") |> DataFrame

x = 1:2048
y = data[1, 2:end] # retrieve the spectrum of the first row

plot(x, y)

The instruction data[1, 2:end] retrieve the correct values, but it seems I need to convert to a different type before passing it to the plot function ?

I get the following error:

ERROR: Cannot convert DataFrameRow{DataFrame, DataFrames.SubIndex{DataFrames.Index, UnitRange{Int64}, UnitRange{Int64}}} to series data for plotting
Stacktrace:
  [1] error(s::String)        
    @ Base .\error.jl:33      
  [2] _prepare_series_data(x::DataFrameRow{DataFrame, DataFrames.SubIndex{DataFrames.Index, UnitRange{Int64}, UnitRange{Int64}}})
    @ RecipesPipeline ~\.julia\packages\RecipesPipeline\CirY4\src\series.jl:8
  [3] _series_data_vector(x::DataFrameRow{DataFrame, DataFrames.SubIndex{DataFrames.Index, UnitRange{Int64}, UnitRange{Int64}}}, plotattributes::Dict{Symbol, Any})
    @ RecipesPipeline ~\.julia\packages\RecipesPipeline\CirY4\src\series.jl:27
  [4] macro expansion
    @ ~\.julia\packages\RecipesPipeline\CirY4\src\series.jl:144 [inlined]
  [5] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)
    @ RecipesPipeline ~\.julia\packages\RecipesBase\92zOw\src\RecipesBase.jl:282
  [6] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~\.julia\packages\RecipesPipeline\CirY4\src\user_recipe.jl:36
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~\.julia\packages\RecipesPipeline\CirY4\src\RecipesPipeline.jl:70
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~\.julia\packages\Plots\SVksJ\src\plot.jl:172
  [9] plot(::Any, ::Vararg{Any, N} where N; kw::Any)
    @ Plots ~\.julia\packages\Plots\SVksJ\src\plot.jl:58
 [10] plot(::Any, ::Any)
    @ Plots ~\.julia\packages\Plots\SVksJ\src\plot.jl:52
 [11] top-level scope
    @ ~\path\to\my\script.jl:18

Thanks for your help!

1 Answers

I am not sure what you need exactly but most likely you need to cast DataFrameRow to a Vector like this:

plot(x, Vector(y))
Related