Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting DataFrames with Julia StatsPlots

This works:

StatsPlots.@df SYN_MM_BM_df plot(
    :t, 
    [:SYN_MM_BM_5, :SYN_MM_BM_10, :SYN_MM_BM_15, :SYN_MM_BM_30]
)

But this does not:

StatsPlots.@df SYN_MM_BM_df plot(
    :t,
    [Symbol(name) for name in names(SYN_MM_BM_df[2:5])]
)
Error: Cannot convert Symbol to series data for plotting

Although:

[Symbol(name) for name in names(SYN_MM_BM_df)[2:5]] ==
    [:SYN_MM_BM_5, :SYN_MM_BM_10, :SYN_MM_BM_15, :SYN_MM_BM_30

is true.

Can anyone explain why? I'd really like to not type all the symbols individually...

like image 765
sacrilego666 Avatar asked Oct 22 '20 03:10

sacrilego666


1 Answers

To work around the limitation that @Nils Gudat highlighted use cols (it treats its contents as a variable and expands it to columns) to get what you want (and use propertynames on data frame to get its column names as symbols directly):

julia> df = DataFrame(x=1:10, y=rand(10), z=rand(10));

julia> @df df plot(:x, cols(propertynames(df)[2:end]))

gives you: enter image description here

which is what I assume you want.

like image 134
Bogumił Kamiński Avatar answered Sep 20 '22 23:09

Bogumił Kamiński