k945
July 19, 2018, 12:41am
1
How do you create subplots from different data frames using StatsPlots? For example, while It is possible to reuse a single data frame to to generate multiple plots
dff = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
@df dff plot(
plot(:a, [:b :c], colour = [:red :blue]),
plot(:a, [:b :c], colour = [:red :blue])
)
what I would like to achieve is
alt = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
alt1 = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
@df dff alt alt1 plot(
plot(:a, [:b :c], colour = [:red :blue]),
plot(:a, [:b :c], colour = [:red :blue]),
plot(:a, [:b :c], colour = [:red :blue])
)
k945
July 19, 2018, 3:55am
2
There are a couple of ways to do achieve panel plots using stats plots; which I missed from the documentation:
one way is outlined in advanced layouts and
from multiple plots and sub-plots layout , it is possible to first create the plot objects and then create the panel plot after e.g.
df1 = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10));
df2 = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
alt = @df df1 plot( :a, [:b :c], colour = [:red :blue])
alt1 = @df df2 plot(plot( :a, [:b :c], colour = [:red :blue])
plot(df1, df2)
piever
July 19, 2018, 6:49am
3
Given that @df
gives you the anonymous that turns a DataFrame in a plot (if you give it only one argument), I think you could also do:
plt1, plt2 = (df1, df2) .|> @df plot(:a, [:b :c])
plot(plt1, plt2)
If you need the same plot on different dataset.
Feel free to make a doc PR with all the techniques that you found useful and feel were not obvious from the current docs!
2 Likes