Skip to content

Commit 4293af3

Browse files
Add violin plots
1 parent 45ae381 commit 4293af3

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/plot.jl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
@shorthands pooleddensity
55
@shorthands traceplot
66
@shorthands corner
7+
@shorthands violinplot
78

89
struct _TracePlot; c; val; end
910
struct _MeanPlot; c; val; end
1011
struct _DensityPlot; c; val; end
1112
struct _HistogramPlot; c; val; end
1213
struct _AutocorPlot; lags; val; end
14+
struct _ViolinPlot; parameters; val; end
1315

1416
# define alias functions for old syntax
1517
const translationdict = Dict(
@@ -18,7 +20,8 @@ const translationdict = Dict(
1820
:density => _DensityPlot,
1921
:histogram => _HistogramPlot,
2022
:autocorplot => _AutocorPlot,
21-
:pooleddensity => _DensityPlot
23+
:pooleddensity => _DensityPlot,
24+
:violinplot => _ViolinPlot
2225
)
2326

2427
const supportedplots = push!(collect(keys(translationdict)), :mixeddensity, :corner)
@@ -184,3 +187,45 @@ end
184187
ar = collect(Array(corner.c.value[:, corner.parameters,i]) for i in chains(corner.c))
185188
RecipesBase.recipetype(:cornerplot, vcat(ar...))
186189
end
190+
191+
@recipe function f(
192+
chains::Chains;
193+
sections = chains.name_map[:parameters],
194+
combined = true
195+
)
196+
197+
st = get(plotattributes, :seriestype, :traceplot)
198+
if st == :violinplot
199+
if combined
200+
parameters = string.(sections)
201+
val = Array(chains)[:, ]
202+
_ViolinPlot(parameters, val)
203+
204+
elseif combined == false
205+
data = Array(chains, append_chains = false)
206+
parameters = vec(["param $(sections[i]).Chain $j"
207+
for i in 1:length(sections),
208+
j in 1:length(data)])
209+
val_vec = vec([data[j][:,i] for i in 1:length(sections), j in 1:length(data)])
210+
n_iter = length(val_vec[1])
211+
n_chains = length(val_vec)
212+
val = zeros(Float64, n_iter, n_chains)
213+
for i in 1:n_iter
214+
for j in 1:n_chains
215+
val[i,j] = val_vec[j][i]
216+
end
217+
end
218+
_ViolinPlot(parameters, val[:,])
219+
else
220+
error("Symbol names are interpreted as parameter names, only compatible with ",
221+
"`colordim = :chain`")
222+
end
223+
end
224+
end
225+
226+
@recipe function f(p::_ViolinPlot)
227+
seriestype := :violin
228+
xaxis --> "Parameter"
229+
p.parameters, p.val
230+
#[collect(skipmissing(p.val[:,k])) for k in 1:size(p.val)]
231+
end

0 commit comments

Comments
 (0)