Last active
December 24, 2019 23:25
-
-
Save kersulis/06a1c4e04e70509f78fe00096cce0e37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
p = joyplot(A) | |
Generate a "joyplot" from data in `A`. Each column of `A` will be | |
plotted with a `plot()` command, and all plots will be stacked | |
vertically. | |
Keyword arguments: | |
* `labels`: a vector of subplot labels having length size(A, 2). | |
* `plot_size`: overall plot size; default is (400, 500). | |
* `subplot_scale`: level of overlap between subplots; default is 1.0. | |
* `color`: vector of colors with length size(A, 2). | |
""" | |
function joyplot( | |
A::Matrix; | |
labels=1:size(A, 2), | |
plot_size=(400, 500), | |
subplot_scale::Float64=1.0, | |
color=distinguishable_colors(size(A, 2) + 2)[3:end] | |
) | |
m, n = size(A) | |
subplot_height = subplot_scale / n | |
subplot_y = range(0; stop=(1 - subplot_height), length=n) | |
p = plot(; | |
size=plot_size, | |
yticks=(subplot_y, labels), | |
grid=:x | |
) | |
peak = maximum(A) | |
for i in 1:n | |
plot!( | |
A[:, i]; | |
inset=(1, bbox(-0.025, subplot_y[i], 1.05, subplot_height, :bottom, :left)), | |
subplot=i + 1, | |
bg_inside=nothing, | |
framestyle=:none, | |
fillrange=0, | |
fillalpha=0.5, | |
fillcolor=color[i], | |
color=color[i], | |
ylim=(0, peak * 1.1) | |
) | |
end | |
return p | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment