-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizer.py
More file actions
48 lines (33 loc) · 1.29 KB
/
visualizer.py
File metadata and controls
48 lines (33 loc) · 1.29 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
46
47
48
import matplotlib.pyplot as plt
import mplcursors as mplc
class Visualizer:
figureNumber = 1
def create_bar_plot(self, labels, sizes, title, xlabel, ylabel, xlabelRot=40):
self.add_figure()
plt.bar(labels, height=sizes)
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.xticks(rotation=xlabelRot)
def create_scatter_plot(self, labels, x, y, c, title, xlabel, ylabel, clabel):
self.add_figure()
ax = plt.scatter(x, y, c=c)
cbar = plt.colorbar()
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
cbar.set_label(clabel, rotation=270, labelpad=15)
cursor = mplc.cursor(ax, hover=True)
@cursor.connect("add")
def on_add(sel):
sel.annotation.set(text="{}\n{}: {}\n{}: {}\n{}: {}".format(labels[sel.target.index], xlabel, x[sel.target.index], ylabel, y[sel.target.index], clabel, c[sel.target.index]))
def create_pie_chart(self, labels, sizes, title, autopct='%1.1f%%'):
self.add_figure()
plt.pie(sizes, labels=labels, autopct=autopct)
plt.axis('equal')
plt.title(title)
def add_figure(self):
plt.figure(self.figureNumber)
self.figureNumber += 1
def show_plots(self):
plt.show()