| 248 | return fig |
| 249 | |
| 250 | def plot_temperature(data, heaters): |
| 251 | fig, ax1 = matplotlib.pyplot.subplots() |
| 252 | ax2 = ax1.twinx() |
| 253 | for heater in heaters.split(','): |
| 254 | heater = heater.strip() |
| 255 | temp_key = heater + ':' + 'temp' |
| 256 | target_key = heater + ':' + 'target' |
| 257 | pwm_key = heater + ':' + 'pwm' |
| 258 | times = [] |
| 259 | temps = [] |
| 260 | targets = [] |
| 261 | pwm = [] |
| 262 | for d in data: |
| 263 | temp = d.get(temp_key) |
| 264 | if temp is None: |
| 265 | continue |
| 266 | times.append(datetime.datetime.utcfromtimestamp(d['#sampletime'])) |
| 267 | temps.append(float(temp)) |
| 268 | pwm.append(float(d.get(pwm_key, 0.))) |
| 269 | targets.append(float(d.get(target_key, 0.))) |
| 270 | ax1.plot_date(times, temps, '-', label='%s temp' % (heater,), alpha=0.8) |
| 271 | if any(targets): |
| 272 | label = '%s target' % (heater,) |
| 273 | ax1.plot_date(times, targets, '-', label=label, alpha=0.3) |
| 274 | if any(pwm): |
| 275 | label = '%s pwm' % (heater,) |
| 276 | ax2.plot_date(times, pwm, '-', label=label, alpha=0.2) |
| 277 | # Build plot |
| 278 | ax1.set_title("Temperature of %s" % (heaters,)) |
| 279 | ax1.set_xlabel('Time') |
| 280 | ax1.set_ylabel('Temperature') |
| 281 | ax2.set_ylabel('pwm') |
| 282 | fontP = matplotlib.font_manager.FontProperties() |
| 283 | fontP.set_size('x-small') |
| 284 | ax1li, ax1la = ax1.get_legend_handles_labels() |
| 285 | ax2li, ax2la = ax2.get_legend_handles_labels() |
| 286 | ax1.legend(ax1li + ax2li, ax1la + ax2la, loc='best', prop=fontP) |
| 287 | ax1.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%H:%M')) |
| 288 | ax1.grid(True) |
| 289 | return fig |
| 290 | |
| 291 | def main(): |
| 292 | # Parse command-line arguments |