10-30-2019, 04:40 AM
Sure, here is the code:
Note that this is the first time I use matplotlib, I might have done some weird things.
Code:
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator)
import json
data = json.load(open('pinetime-battery-log.json'))
# Set things up.
fig, ax = plt.subplots(figsize=(10, 8))
# Massage the data to be easier to interpret, and draw it.
xaxis = [e[0] / 60 / 60 for e in data]
yaxis = [e[1] * 2 / (4095 / 3.0) for e in data]
ax.scatter(xaxis, yaxis, s=1)
# Draw some labels.
plt.xlabel('Time (hours)')
plt.ylabel('Voltage')
plt.title('Battery discharge curve')
# Draw the grid.
plt.grid(which='both')
plt.minorticks_on()
plt.grid(b=True, which='minor', alpha=0.3)
ax.yaxis.set_major_locator(MultipleLocator(0.1))
ax.xaxis.set_major_locator(MultipleLocator(1))
ax.xaxis.set_minor_locator(MultipleLocator(10/60))
# Show the chart.
plt.show()
Note that this is the first time I use matplotlib, I might have done some weird things.