StatsPlots.jl
StatsPlots.jl copied to clipboard
Color gradient by group factor
My apologies if this capability exists or is addressed somewhere in the documentation. What I would like to do is apply a color gradient according to a grouping factor. I asked the community on Discourse, but no one replied. I've hit a wall.
Here is one of my attempts:
using DataFrames, StatsPlots, Distributions
x = 1:10
linear(b0, b1, x) = b0 + b1*x
B0 = [0,10]
B1 = range(.5, stop=1, length=5)
y = [linear.(b0, b1, x) for b1 in B1 for b0 in B0]
y = vcat(y...)
df = DataFrame(group = repeat(0:1,inner=50), slope = repeat(repeat(B1, inner=10), outer =2),
x = repeat(x,outer=10), y = y)
@df df plot(:x, :y, group = (:group,:slope), legend=false, palette = cgrad(:viridis,:slope))
The desired result is to apply the same color to each line with the same slope. If this capability does not exist, would it be possible to add? One useful application is exploring the behavior of a model with different parameter values. So I think this would be useful beyond my current use case.