Gadfly.jl plots

To plot the Chains via Gadfly.jl, use the DataFrames constructor:

using DataFrames
using CategoricalArrays
using Gadfly
using MCMCChains

chn = Chains(randn(100, 2, 3), [:A, :B])
df = DataFrame(chn)
df[!, :chain] = categorical(df.chain)

plot(df, x=:A, color=:chain, Geom.density, Guide.ylabel("Density"))
Example block output

Multiple parameters

Or, to show multiple parameters in one plot, use DataFrames.stack

sdf = stack(df, names(chn), variable_name=:parameter)
first(sdf, 5)
5×4 DataFrame
Rowiterationchainparametervalue
Int64Cat…StringFloat64
111A1.69865
221A-0.770567
331A1.15444
441A0.771121
551A-0.716144

and Gadfly.Geom.subplot_grid

plot(sdf, ygroup=:parameter, x=:value, color=:chain,
    Geom.subplot_grid(Geom.density), Guide.ylabel("Density"))
Example block output

This is very flexible. For example, we can look at the first two chains only by using DataFrames.filter

first_chain = filter([:chain] => c -> c == 1 || c == 2, sdf)

plot(first_chain, xgroup=:parameter, ygroup=:chain, x=:value,
    Geom.subplot_grid(Geom.density, Guide.xlabel(orientation=:horizontal)),
    Guide.xlabel("Parameter"), Guide.ylabel("Chain"))
Example block output

Trace

plot(first_chain, ygroup=:parameter, x=:iteration, y=:value, color=:chain,
    Geom.subplot_grid(Geom.point), Guide.ylabel("Sample value"))
Example block output