I have a line graph that I'm plotting in python. The last thing that I need to do is add a line telling it to color a section of the graph red if the slope is greater that 25. How would I do this?
Here's what I have so far.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data = pd.read_csv('ReactorStartupTemps.csv')
print(data)
plt.rcParams["figure.figsize"] = [5, 4]
plt.rcParams["figure.autolayout"] = True
plt.xlabel('Time [min]', fontdict={'fontname': 'Times New Roman',
'style': 'italic'})
plt.ylabel('Temperature [C]', fontdict={'fontname': 'Times New Roman',
'style': 'italic'})
plt.title('Reactor Startup Temperatures', fontdict={'fontname': 'Times
New Roman', 'style': 'italic'})
[slope, intercept] = np.polyfit(data.Time, data.Temp, 1)
if slope > 25:
plt.plot(data.Time, data.Temp, color="red", linewidth=1.5)
else:
plt.plot(data.Time, data.Temp, color="black", linewidth=1.5)
plt.minorticks_on()
plt.grid(which='major', color='grey', linewidth=.8)
plt.grid(which='minor', color='lightgrey', linewidth=.4, ls='--')
plt.show()
What the graph needs to look like:
Graph as of now:
