2 Created on Feb 25, 2014 7 import matplotlib.dates
as md
9 from mpl_toolkits.mplot3d
import Axes3D
36 def labels(self, title='', units=''):
40 def plot1(self, figNum, time, data, title='', units='', options=''):
51 fig.canvas.set_window_title(
"Figure %d - %s" % (figNum,self.
preTitle))
52 plt.title(
"%s"%(self.
title))
53 plt.plot(time, data, options)
54 plt.ylabel(
'(%s)'%(self.
units))
55 plt.xlabel(
'Time (s)')
59 def plot2(self, figNum, time1, data1, time2, data2, title='', units='', options=''):
70 fig.canvas.set_window_title(
"Figure %d - %s" % (figNum,self.
preTitle))
71 plt.title(
"%s"%(self.
title))
72 plt.plot(time1, data1, options)
73 plt.plot(time2, data2, options)
74 plt.ylabel(
'(%s)'%(self.
units))
75 plt.xlabel(
'Time (s)')
79 def plot3Axes(self, figNum, time, data, title='', units='', xlabel='Time (s)
', options='', xlim=None, ylim=None): 80 fig = plt.figure(figNum) 88 fig.canvas.set_window_title(
"Figure %d - %s" % (figNum,self.
preTitle))
89 if not figNum
in self.
sharex.keys():
90 self.
sharex[figNum] = plt.subplot(3,1,1)
94 subplt = plt.subplot(3,1,1, sharex=self.
sharex[figNum])
97 plt.title(
"%s"%(self.
title))
98 plt.ylabel(
'(%s)'%(self.
units))
102 subplt.set_xlim(xlim)
104 subplt.set_ylim(ylim)
106 dates=[dt.datetime.fromtimestamp(ts)
for ts
in time]
107 datenums=md.date2num(dates)
109 plt.xticks( rotation=25 )
112 xfmt = md.DateFormatter(
'%H:%M:%S.%f')
114 xfmt = md.DateFormatter(
'%H:%M:%S')
115 ax.xaxis.set_major_formatter(xfmt)
116 plt.plot(datenums, data[:,0], options)
118 plt.plot(time, data[:,0], options)
121 subplt = plt.subplot(3,1,2, sharex=self.
sharex[figNum])
124 plt.ylabel(
'(%s)'%(self.
units))
128 subplt.set_xlim(xlim)
130 subplt.set_ylim(ylim)
132 dates=[dt.datetime.fromtimestamp(ts)
for ts
in time]
133 datenums=md.date2num(dates)
135 plt.xticks( rotation=25 )
138 xfmt = md.DateFormatter(
'%H:%M:%S.%f')
140 xfmt = md.DateFormatter(
'%H:%M:%S')
141 ax.xaxis.set_major_formatter(xfmt)
142 plt.plot(datenums, data[:,1], options)
144 plt.plot(time, data[:,1], options)
147 subplt = plt.subplot(3,1,3, sharex=self.
sharex[figNum])
150 plt.ylabel(
'(%s)'%(self.
units))
154 subplt.set_xlim(xlim)
156 subplt.set_ylim(ylim)
158 dates=[dt.datetime.fromtimestamp(ts)
for ts
in time]
159 datenums=md.date2num(dates)
161 plt.xticks( rotation=25 )
164 xfmt = md.DateFormatter(
'%H:%M:%S.%f')
166 xfmt = md.DateFormatter(
'%H:%M:%S')
167 ax.xaxis.set_major_formatter(xfmt)
168 plt.plot(datenums, data[:,2], options)
170 plt.plot(time, data[:,2], options)
180 if not figNum
in self.
sharex.keys():
181 self.
sharex[figNum] = plt.subplot(3,1,1)
184 subplt = plt.subplot(3,1,1, sharex=self.
sharex[figNum])
185 yl = subplt.get_ylim()
186 med = (yl[1] - yl[0])*0.5 + yl[0]
187 yl = [med-yspan*0.5,med+yspan*0.5]
191 subplt = plt.subplot(3,1,2, sharex=self.
sharex[figNum])
192 yl = subplt.get_ylim()
193 med = (yl[1] - yl[0])*0.5 + yl[0]
194 yl = [med-yspan*0.5,med+yspan*0.5]
198 subplt = plt.subplot(3,1,3, sharex=self.
sharex[figNum])
199 yl = subplt.get_ylim()
200 med = (yl[1] - yl[0])*0.5 + yl[0]
201 yl = [med-yspan*0.5,med+yspan*0.5]
205 if not figNum
in self.
f.keys():
206 self.
f[figNum] =
cObj()
207 self.
f[figNum].fig = plt.figure()
208 self.
f[figNum].ax = self.
f[figNum].fig.add_subplot(111, projection=
'3d')
209 self.
f[figNum].fig.canvas.set_window_title(
"%s__%s" % (self.
preTitle, figTitle))
210 return self.
f[figNum].fig, self.
f[figNum].ax
212 def subplots(self, figNum, numRows, figTitle='', sharex=True, numCols=1):
216 if not figNum
in self.
f.keys():
217 self.
f[figNum] =
cObj()
218 self.
f[figNum].fig, self.
f[figNum].ax = plt.subplots(numRows,numCols, sharex=sharex)
220 self.
f[figNum].fig.canvas.set_window_title(
"%s__%s" % (self.
preTitle, figTitle))
222 return self.
f[figNum].fig, self.
f[figNum].ax
224 def subplotSingle(self, ax, time, data, title='', ylabel='', xlabel='', options=''):
234 ax.set_title(
"%s"%(title))
236 ax.set_xlabel(
'(%s)'%(xlabel))
238 ax.set_ylabel(
'(%s)'%(ylabel))
242 dates=[dt.datetime.fromtimestamp(ts)
for ts
in time]
243 datenums=md.date2num(dates)
245 ax.xticks( rotation=25 )
248 xfmt = md.DateFormatter(
'%M:%S.%f')
251 xfmt = md.DateFormatter(
'%M:%S')
252 ax.xaxis.set_major_formatter(xfmt)
257 if isinstance(options, str):
258 ax.plot(time, data, options)
260 ax.plot(time, data, **options)
263 def subplotSingle2x(self, figNum, plotNum, numRows, numCols, time, data, title='', units='', options=''):
265 print(
"subplotSingle2x")
274 fig.canvas.set_window_title(
"%s" % (figNum,self.
preTitle))
275 if not figNum
in self.
sharex.keys():
276 self.
sharex[figNum] = plt.subplot(numRows,numCols,plotNum)
277 plt.plot(time, data, options)
279 plt.subplot(numRows,numCols,plotNum,sharex=self.
sharex[figNum])
282 plt.title(
"%s"%(self.
title))
283 plt.plot(time, data, options)
284 plt.ylabel(
'(%s)'%(self.
units))
289 med = (yl[1] - yl[0])*0.5 + yl[0]
290 yl = [med-yspan*0.5,med+yspan*0.5]
295 span = yl[1] - yl[0];
297 med = span*0.5 + yl[0]
298 yl = [med-yspan*0.5,med+yspan*0.5]
301 def plotNE(self, figNum, north, east, title='', units='', options=''):
313 fig.canvas.set_window_title(
"%s" % (self.
preTitle))
314 plt.title(
"%s"%(self.
title))
315 plt.plot(east, north, options)
316 plt.xlabel(
'East (%s)' %(self.
units))
317 plt.ylabel(
'North (%s)'%(self.
units))