Skip to content

Commit 4674ea5

Browse files
Modify default size and code refactoring
1 parent 4293af3 commit 4674ea5

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/plot.jl

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct _MeanPlot; c; val; end
1111
struct _DensityPlot; c; val; end
1212
struct _HistogramPlot; c; val; end
1313
struct _AutocorPlot; lags; val; end
14-
struct _ViolinPlot; parameters; val; end
14+
struct _ViolinPlot; parameters; val; total_chains; end
1515

1616
# define alias functions for old syntax
1717
const translationdict = Dict(
@@ -195,27 +195,28 @@ end
195195
)
196196

197197
st = get(plotattributes, :seriestype, :traceplot)
198+
total_chains = 0
198199
if st == :violinplot
199200
if combined
200201
parameters = string.(sections)
201202
val = Array(chains)[:, ]
202-
_ViolinPlot(parameters, val)
203-
203+
total_chains = Integer(size(chains.value.data)[3])
204+
_ViolinPlot(parameters, val, total_chains)
204205
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)])
206+
chain_arr = Array(chains, append_chains = false)
207+
parameters = ["param $(sections[i]).Chain $j"
208+
for i in 1:length(sections)
209+
for j in 1:length(chain_arr)]
210+
val_vec = [chain_arr[j][:,i]
211+
for i in 1:length(sections)
212+
for j in 1:length(chain_arr)]
210213
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
214+
total_chains = length(val_vec)
215+
val = zeros(Float64, n_iter, total_chains)
216+
for i in 1:total_chains
217+
val[:,i] = val_vec[:][i]
217218
end
218-
_ViolinPlot(parameters, val[:,])
219+
_ViolinPlot(parameters, val[:,], total_chains)
219220
else
220221
error("Symbol names are interpreted as parameter names, only compatible with ",
221222
"`colordim = :chain`")
@@ -224,8 +225,18 @@ end
224225
end
225226

226227
@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)]
228+
@series begin
229+
seriestype := :violin
230+
xaxis --> "Parameter"
231+
size --> (150*p.total_chains, 500)
232+
p.parameters, p.val
233+
end
234+
235+
@series begin
236+
seriestype := :boxplot
237+
bar_width --> 0.1
238+
linewidth --> 2
239+
fillalpha --> 0.8
240+
p.parameters, p.val
241+
end
231242
end

0 commit comments

Comments
 (0)