I am trying to plot a single line graph with different color (positive value: blue, negative value: red) There is a csv file which is updating data continuously, I am reading the data and update the graph when a new value is enter to that csv file.
Below are my code and the result.
def main():
plt.style.use('fivethirtyeight')
fig = plt.figure()
fig.set_figheight(4)
fig.set_figwidth(8)
def animate(i):
data = pd.read_csv('data.csv')
if len(data['y']) > 200:
x = list(range(200))
y = data['y'][-200:]
else:
x = list(range(len(data['y'])))
y = data['y']
fig.clf()
# Adds subplot on position 1.
ax = fig.add_subplot(211)
# Set value to subplot pos 2.
ax.plot(x, y))
#ax.scatter(x, y, c=y, cmap='Reds')
plt.tight_layout()
ani = FuncAnimation(fig, animate, interval=0.00001)
plt.tight_layout()
plt.show()
How can I change the color of the line to red when the value is negative?