-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_barplot_generator.py
More file actions
42 lines (35 loc) · 1.02 KB
/
random_barplot_generator.py
File metadata and controls
42 lines (35 loc) · 1.02 KB
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
import numpy
import pandas
import seaborn
from pathlib import Path
import matplotlib.pyplot as plt
output = Path("barplots")
output.mkdir(exist_ok=True)
colors = {
"blue": "#456990",
"red": "#EC5B60",
"green": "#41B4A1"
}
def main():
n = 15
N = 10
names = ["healthy", "diseased"]
probabilities = numpy.asarray([
[1, 1, 1],
[1, .1, .1]
])
probabilities /= probabilities.sum(axis=1)[..., numpy.newaxis]
for i, proba in enumerate(probabilities):
(output / names[i]).mkdir(exist_ok=True)
for j in range(N):
sample = numpy.random.choice(["rood", "groen", "blauw"], size=n, p=proba)
ax = seaborn.countplot(
x=sample,
order=["rood", "groen", "blauw"],
palette=[colors["red"], colors["green"], colors["blue"]]
)
ax.set_xlabel("")
plt.savefig(str(output / names[i] / f"{j}.png"), bbox_inches="tight")
plt.close()
if __name__ == "__main__":
main()