Код: Выделить всё
# converting 0 values to None
points = [None if x == 0 else x for x in chart_data ['points']]
x = chart_data ['time']
fig, ax1 = plt.subplots ()
ax1.set_xlabel ('Date')
ax1.set_ylabel ('Val')
plt.ylabel ('Val2')
ax2 = ax1.twinx ()
ax1.plot (x, chart_data ['line_points'], label='line', marker='', c='blue', linestyle='-')
ax2.scatter (x, points, label='Points', marker='x', c='green', linestyle='')
# code added to display trend line
z = np.polyfit (x, points, 1)
p = np.poly1d (z)
ax2.plot (x, p (x), "r-")
plt.legend (facecolor='lightgray', edgecolor='gray')
plt.show()
Код: Выделить всё
TypeError: unsupported operand type(s) for +: 'Timestamp' and 'float'
Код: Выделить всё
z = np.polyfit ([float (t.timestamp ()) for t in x], points, 1)
Код: Выделить всё
TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'
Подробнее здесь: https://stackoverflow.com/questions/783 ... -on-y-axis