-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_utils.py
More file actions
46 lines (34 loc) · 1.15 KB
/
plot_utils.py
File metadata and controls
46 lines (34 loc) · 1.15 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
43
44
45
import matplotlib.pyplot as plt
import os
import numpy as np
import pandas as pd
import glob
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
def rand_jitter(arr):
stdev = .005 * (max(arr) - min(arr))
return arr + np.random.randn(len(arr)) * stdev
def filter(df, **kwargs):
bool_index = None
for key, value in kwargs.items():
if isinstance(value, list):
_bool_index = df[key].isin(value)
else:
_bool_index = df[key] == value
if bool_index is None:
bool_index = _bool_index
else:
bool_index = bool_index & _bool_index
return df[bool_index]
def create_chart_grid(charts, row_width):
charts_merged = None
charts_row = None
col = 0
for i in range(0, len(charts)):
col = i % row_width
if col == 0:
charts_merged = charts_row if charts_merged is None else charts_merged & charts_row
charts_row = None
charts_row = charts[i] if charts_row is None else charts_row | charts[i]
if col:
charts_merged = charts_row if charts_merged is None else charts_merged & charts_row
return charts_merged