graphstats: Support graphing multiple heaters

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-04-29 15:53:28 -04:00
parent 0a4a64058d
commit d1946fb6ed
1 changed files with 28 additions and 22 deletions

View File

@ -214,7 +214,11 @@ def plot_frequency(data, mcu):
ax1.grid(True) ax1.grid(True)
return fig return fig
def plot_temperature(data, heater): def plot_temperature(data, heaters):
fig, ax1 = matplotlib.pyplot.subplots()
ax2 = ax1.twinx()
for heater in heaters.split(','):
heater = heater.strip()
temp_key = heater + ':' + 'temp' temp_key = heater + ':' + 'temp'
target_key = heater + ':' + 'target' target_key = heater + ':' + 'target'
pwm_key = heater + ':' + 'pwm' pwm_key = heater + ':' + 'pwm'
@ -230,16 +234,18 @@ def plot_temperature(data, heater):
temps.append(float(temp)) temps.append(float(temp))
pwm.append(float(d.get(pwm_key, 0.))) pwm.append(float(d.get(pwm_key, 0.)))
targets.append(float(d.get(target_key, 0.))) targets.append(float(d.get(target_key, 0.)))
ax1.plot_date(times, temps, '-', label='%s temp' % (heater,), alpha=0.8)
if any(targets):
label = '%s target' % (heater,)
ax1.plot_date(times, targets, '-', label=label, alpha=0.3)
if any(pwm):
label = '%s pwm' % (heater,)
ax2.plot_date(times, pwm, '-', label=label, alpha=0.2)
# Build plot # Build plot
fig, ax1 = matplotlib.pyplot.subplots() ax1.set_title("Temperature of %s" % (heaters,))
ax1.set_title("Temperature of heater %s" % (heater,))
ax1.set_xlabel('Time') ax1.set_xlabel('Time')
ax1.set_ylabel('Temperature') ax1.set_ylabel('Temperature')
ax1.plot_date(times, temps, 'r', label='Measured temp', alpha=0.8)
ax1.plot_date(times, targets, 'g', label='Target', alpha=0.8)
ax2 = ax1.twinx()
ax2.set_ylabel('pwm') ax2.set_ylabel('pwm')
ax2.plot_date(times, pwm, 'y', label='pwm', alpha=0.8)
fontP = matplotlib.font_manager.FontProperties() fontP = matplotlib.font_manager.FontProperties()
fontP.set_size('x-small') fontP.set_size('x-small')
ax1.legend(loc='best', prop=fontP) ax1.legend(loc='best', prop=fontP)