-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_plot.py
45 lines (34 loc) · 1.11 KB
/
graph_plot.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 7 14:10:16 2018
@author: Arpit
"""
import numpy as np
import matplotlib.pyplot as plt
class GraphPlot:
def __init__(self, name="graph-plot", xlabel="X-axis", ylabel="Y-axis"):
self.name = name
self.xlabel = xlabel
self.ylabel = ylabel
self.plots = {}
self.labels = {}
def addPlot(self, plot, label=None):
self.plots[plot] = []
if label is None:
label = len(self.plots)
self.labels[plot] = label
def addData(self, data, plot):
self.plots[plot].append(data)
def plot(self):
fig = plt.figure()
for key,value in self.plots.items():
plot = np.array(value)
X = list(plot[:, 0])
Y = list(plot[:, 1])
plt.plot(X, Y, label=self.labels[key])
plt.ylabel(self.ylabel)
plt.xlabel(self.xlabel)
plt.legend(loc = "best")
plt.savefig("/Users/Arpit/Desktop/" + self.name + 'chart.png')
plt.close(fig)