Matplotlib.pylot
Plot both variables with plt.scatter
, add a label parameter, then call the legend with plt.legend
:
tc1 = [24,25,26,27]
tc2 = [28,29,31,33]
t = [1,2,3,4]
plt.scatter(t, tc1, label = 'thermocouple 1', color = 'blue')
plt.scatter(t, tc2, label = 'thermocouple 2', color = 'red')
plt.xlabel('Time(seconds)')
plt.ylabel('Temperature(Celsius)')
plt.title('Voltage Over Time')
plt.legend()
plt.show()

Seaborn:
Seaborn has a nice built in hue
feature that does the heavy lifting for you:
import seaborn as sns
df = pd.DataFrame(zip(tc1, tc2, t), columns = ['thermocouple 1', 'thermocouple 2', 'time']).melt('time')
sns.scatterplot(df, x = 'time', y = 'value', hue = 'variable')
plt.xlabel('Time(seconds)')
plt.ylabel('Temperature(Celsius)')
plt.title('Voltage Over Time')
plt.legend(title = '')
plt.show()

Pandas Plot:
Using Pandas, you can use plot.line
and pivot
to change the color based on the different variable (thermocouple 1 vs thermocouple 2):
(pd.DataFrame(zip(tc1, tc2, t), columns = ['thermocouple 1', 'thermocouple 2', 'time'])
.melt('time')
.pivot(columns='variable', index='time', values='value') # pivot is needed to add colors based on the variable
.plot.line(style = '.', markersize = 20, # change the line style to just show markers (dots)
title = 'Voltage Over Time',
xlabel = 'Time(seconds)',
ylabel = 'Temperature(Celsius)')
.legend()) # Remove legend title
plt.show()
