-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
58 lines (48 loc) · 1.82 KB
/
utils.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
52
53
54
55
56
57
58
import numpy as np
import matplotlib.pyplot as plt
def plot_hist_sum(data, r_labels, ylabel, xlabel, title, x_tick_labels=None, adjacent_bars=True):
"""
plots Histogram of sum
plots multiple bars
"""
n_rows = len(r_labels)
total_bars_width = 0.8
bar_width = total_bars_width / n_rows
# bins = np.linspace(1, d, d)
bins = np.arange(data.shape[1]) + 1 # d = data.shape[1]
fig, ax = plt.subplots(figsize=(10, 6))
for i in range(n_rows):
if adjacent_bars:
ax.bar(x=bins + (i * bar_width) - total_bars_width / 2 + bar_width / 2,
height=data[i], width=bar_width, align='center', label=r_labels[i])
else: # overlapping\superimposed bars
ax.bar(x=bins, height=data[i], alpha=0.75, width=total_bars_width, align='center', label=r_labels[i])
ax.legend(loc='best')
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.set_xticks(bins)
if x_tick_labels is not None:
ax.set_xticklabels(x_tick_labels)
ax.set_title(title)
def plot_hist_count(data, r_labels, ylabel, xlabel, title, x_tick_labels=None, adjacent_bars=True):
"""
plots Histogram of count
"""
n_rows = len(r_labels)
total_bars_width = 0.8
bar_width = total_bars_width / n_rows
# bins = np.linspace(1, d, d)
bins = np.arange(data.shape[1]) + 1 # d = data.shape[1]
fig, ax = plt.subplots(figsize=(10, 6))
if adjacent_bars:
ax.hist(x=data, bins=bins, label=r_labels)
else: # overlapping\superimposed bars
for i in range(n_rows): # alpha=0.5
ax.hist(x=data[i], bins=bins, alpha=0.5, label=r_labels[i])
ax.legend(loc='best')
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.set_xticks(bins)
if x_tick_labels is not None:
ax.set_xticklabels(x_tick_labels)
ax.set_title(title)