Hello,
So I an creating a graph to display ‘temp’ against ‘time’ reading data from a live temp module. I have created a brief example in notepad++ to confirm it works. I would like to display the temp curve over 60 minutes and append ‘channel_1_temp[]’ and ‘time_minutes_temp[]’ from the start of the test - so essentially the graph grows over time. Below are my notepad++ and the actually example from the live temp module.
The problem I am having with the ‘temp module example’, is the arrays don’t grow in size. They just stay at two elements. This is odd because the notepad++ example grew in size? Also looking at the below output, the ‘channel_1_temp [ 1 22]’ has a leading space at the start that seems to grow when left running?
Im sure I am missing something simple but I cannot see what I am doing wrong.
Many thanks,
Tuurbo46
Notepad++ example:
import numpy as np
import matplotlib.pyplot as plt
time_minutes = np.array([10, 20, 30, 40, 50]) # Minutes
temp_c = np.array([18, 20, 25, 25, 26]) # Celsius
time_minutes = np.append(time_minutes, "60") # add a time to the end of array
temp_c = np.append(temp_c, "30") # add a temp to the end of array
plt.ylabel("C")
plt.xlabel("Minutes")
plt.plot(temp_c, time_minutes)
plt.show()
Temp module example called every 1 minute:
def temperature_graph():
global time_minutes_temp
global channel_1_temp
global temp_chl_1
global count
count =+ 1
time_minutes_temp = np.array([1]) # Minutes
channel_1_temp = np.array([1]) # Centigrade
#---- Append time array by 1 minute ----
time_minutes_temp = np.append(time_minutes_temp, [count])
#---- Convert global temp float value to an int ----
temp_chl_1_int = temp_chl_1
temp_chl_1_int = int(temp_chl_1_int)
#---- Append temp array with latest temp value
channel_1_temp = np.append(channel_1_temp, [temp_chl_1_int])
print('time_minutes_temp', time_minutes_temp)
print('channel_1_temp', channel_1_temp)
plt.ylabel("C")
plt.xlabel("Minutes")
plt.plot(channel_1_temp, time_minutes_temp)
plt.show()
Temp module output:
time_minutes_temp [1 1]
channel_1_temp [ 1 22]
time_minutes_temp [1 1]
channel_1_temp [ 1 22]