-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
136 lines (124 loc) · 3.64 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#-*- coding: utf-8 -*-
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from pdb import set_trace as debug
def plot(x, y, title='', xlabel='', ylabel=''):
plt.clf()
figure = plt
figure.scatter(x, y)
figure.title(title)
figure.xlabel(xlabel)
figure.ylabel(ylabel)
figure.autoscale(tight=True)
figure.grid()
figure.savefig(title + '.png', format='png')
plt.close()
def multiPlot(plotArray, title='', xlabel='', ylabel='', xscale='linear', yscale='linear'):
"""
plotArray is of the form: [[X1, Y1], [X2, Y2]]
Where Xi, Yi are arrays of of the values to plot.
"""
plt.clf()
figure = plt
figure.title(title)
figure.xlabel(xlabel)
figure.ylabel(ylabel)
markers = '+,.1234'
colors = 'rbgyo'
if len(plotArray) > 5:
print 'More than 5 plots given as parameters (plotArray)'
return False
for i, (Xi, Yi) in enumerate(plotArray):
figure.scatter(
Xi,
Yi,
marker=markers[i],
c=colors[i]
)
figure.xscale(xscale)
figure.yscale(yscale)
figure.autoscale(tight=True)
figure.grid()
figure.savefig(title + '.png', format='png')
plt.close()
def plotLines(plotArray, title='', xlabel='', ylabel='', xscale='linear', yscale='linear'):
"""
plotArray is of the form: [[X1, Y1], [X2, Y2]]
Where Xi, Yi are arrays of of the values to plot.
"""
plt.clf()
figure = plt
figure.title(title)
figure.xlabel(xlabel)
figure.ylabel(ylabel)
markers = '+,.1234'
colors = 'rbgyo'
if len(plotArray) > 5:
print 'More than 5 plots given as parameters (plotArray)'
return False
for i, (Xi, Yi) in enumerate(plotArray):
figure.plot(
Xi,
Yi,
marker=markers[i],
c=colors[i]
)
figure.xscale(xscale)
figure.yscale(yscale)
figure.autoscale(tight=True)
figure.grid()
figure.savefig(title + '.png', format='png')
plt.close()
def plot3D(plotArray, title='', xlabel='', ylabel='', zlabel=''):
"""
Given a plotArray = [X, Y, Z] this will save a 3D
figure of the scattered data.
"""
X, Y, Z = plotArray
figure = plt.figure()
ax = Axes3D(figure)
ax.scatter(X, Y, Z)
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_zlabel(zlabel)
figure.savefig(title + '.png', format='png')
plt.close(figure)
def plotLines3D(plotArray, title='', xlabel='', ylabel='', zlabel=''):
"""
Given a plotArray = [X, Y, Z] this will save a 3D
figure of the plotted data.
"""
X, Y, Z = plotArray
figure = plt.figure()
ax = Axes3D(figure)
ax.plot_wireframe(X, Y, Z)
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_zlabel(zlabel)
figure.savefig(title + '.png', format='png')
plt.close(figure)
def plotSurface3D(plotArray, title='', xlabel='', ylabel='', zlabel=''):
"""
Given a plotArray = [X, Y, Z] this will save a 3D surface
figure of the plotted data.
"""
X, Y, Z = plotArray
figure = plt.figure()
ax = Axes3D(figure)
ax.plot_surface(X, Y, Z)
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_zlabel(zlabel)
figure.savefig(title + '.png', format='png')
plt.close(figure)
if __name__ == '__main__':
x = [i for i in xrange(10)]
y = [i**2 for i in xrange(10)]
x1 = [i for i in xrange(10)]
y2 = [i**3 for i in xrange(10)]
x3 = [i for i in xrange(10)]
y3 = [i*3 for i in xrange(10)]
plotLines3D([x, y, y3], title="test")