-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrainclouds.py
51 lines (41 loc) · 1.49 KB
/
rainclouds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# %%
import numpy as np
import pymatviz as pmv
pmv.set_plotly_template("pymatviz_white")
# Set up the RNG with a seed for reproducibility
rng = np.random.default_rng(seed=0)
# %% Example 1: Two bimodal distributions
data_bimodal = {
"Distribution A": np.concatenate(
[rng.normal(-2, 0.5, 600), rng.normal(2, 0.5, 400)]
),
"Distribution B": np.concatenate(
[rng.normal(-1, 0.3, 400), rng.normal(3, 0.7, 600)]
),
}
fig_bi = pmv.rainclouds(data_bimodal)
fig_bi.layout.title.update(text="Raincloud Plot: Two Bimodal Distributions", x=0.5)
fig_bi.layout.xaxis.title = "Value"
fig_bi.layout.yaxis.title = "Distribution"
fig_bi.layout.margin.t = 40
fig_bi.show()
pmv.io.save_and_compress_svg(fig_bi, "rainclouds-bimodal")
# %% Example 2: Three trimodal distributions
data_trimodal = {
"Distribution X": np.concatenate(
[rng.normal(-3, 0.4, 300), rng.normal(0, 0.3, 400), rng.normal(3, 0.5, 300)]
),
"Distribution Y": np.concatenate(
[rng.normal(-2, 0.3, 350), rng.normal(1, 0.4, 350), rng.normal(4, 0.6, 300)]
),
"Distribution Z": np.concatenate(
[rng.normal(-4, 0.5, 250), rng.normal(-1, 0.3, 450), rng.normal(2, 0.4, 300)]
),
}
fig_tri = pmv.rainclouds(data_trimodal)
fig_tri.layout.title.update(text="Raincloud Plot: Three Trimodal Distributions", x=0.5)
fig_tri.layout.xaxis.title = "Value"
fig_tri.layout.yaxis.title = "Distribution"
fig_tri.layout.margin.t = 40
fig_tri.show()
pmv.io.save_and_compress_svg(fig_tri, "rainclouds-trimodal")