Mercurial > ~darius > hgwebdir.cgi > agl
comparison agl.py @ 9:e2807c99e107
Fix battery charge scale to 0-100.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 11 Sep 2017 16:49:00 +0930 |
parents | 22d31cee19b1 |
children | 70cc1e874157 |
comparison
equal
deleted
inserted
replaced
8:22d31cee19b1 | 9:e2807c99e107 |
---|---|
208 xdata = map(lambda f: f.replace(tzinfo = utc).astimezone(lt), ary[:,0]) | 208 xdata = map(lambda f: f.replace(tzinfo = utc).astimezone(lt), ary[:,0]) |
209 for idx in range(len(cols)): | 209 for idx in range(len(cols)): |
210 ydata = ary[:,idx + 1] | 210 ydata = ary[:,idx + 1] |
211 if cols[idx] in convs: | 211 if cols[idx] in convs: |
212 ydata = convs[cols[idx]](ydata) | 212 ydata = convs[cols[idx]](ydata) |
213 | |
214 if cols[idx] in scale_limits: | |
215 scale_min = scale_limits[cols[idx]][0] | |
216 scale_max = scale_limits[cols[idx]][1] | |
217 else: | |
218 scale_min = None | |
219 scale_max = None | |
220 | |
213 if units[cols[idx]] == yaxisunits1: | 221 if units[cols[idx]] == yaxisunits1: |
214 ax1lines.append([xdata, ydata, names[cols[idx]], colourlist[colouridx]]) | 222 ax = ax1lines |
215 else: | 223 else: |
216 ax2lines.append([xdata, ydata, names[cols[idx]], colourlist[colouridx]]) | 224 ax = ax2lines |
225 ax.append([xdata, ydata, names[cols[idx]], colourlist[colouridx], scale_min, scale_max]) | |
217 colouridx += 1 | 226 colouridx += 1 |
218 | 227 |
219 if fname == None: | 228 if fname == None: |
220 import matplotlib.pylab | 229 import matplotlib.pylab |
221 fig = matplotlib.pylab.figure() | 230 fig = matplotlib.pylab.figure() |
225 | 234 |
226 ax1 = fig.add_subplot(111) | 235 ax1 = fig.add_subplot(111) |
227 ax1.set_ylabel(yaxisunits1) | 236 ax1.set_ylabel(yaxisunits1) |
228 | 237 |
229 for line in ax1lines: | 238 for line in ax1lines: |
230 ax1.plot(line[0], line[1], label = line[2]) | 239 ax1.plot(line[0], line[1], label = line[2], color = line[3]) |
240 if line[4] != None and line[5] != None: | |
241 ax1.set_ylim((line[4], line[5])) | |
231 | 242 |
232 ax1.legend(loc = 'upper left') | 243 ax1.legend(loc = 'upper left') |
233 | 244 |
234 if yaxisunits2 != None: | 245 if yaxisunits2 != None: |
235 ax2 = ax1.twinx() | 246 ax2 = ax1.twinx() |
236 ax2.set_ylabel(yaxisunits2) | 247 ax2.set_ylabel(yaxisunits2) |
237 | 248 |
238 for line in ax2lines: | 249 for line in ax2lines: |
239 ax2.plot(line[0], line[1], label = line[2], color = line[3]) | 250 ax2.plot(line[0], line[1], label = line[2], color = line[3]) |
251 if line[4] != None and line[5] != None: | |
252 ax2.set_ylim(bottom = line[4], top = line[5]) | |
240 ax2.legend(loc = 'upper right') | 253 ax2.legend(loc = 'upper right') |
241 | 254 |
242 ndays = int(max(1, round(((end - start).total_seconds()) / 86400))) | 255 ndays = int(max(1, round(((end - start).total_seconds()) / 86400))) |
243 for ax in fig.get_axes(): | 256 for ax in fig.get_axes(): |
244 ax.set_title('%s to %s' % (start.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d'))) | 257 ax.set_title('%s to %s' % (start.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d'))) |