Reputation: 11
so for the context. I build a small arduino based weather station and want to plot my data for some analysis. I store my measuments in a .json file and want to draw my diagram with these values.
def getVal():
data = db.all()
tempData = []
voltData = []
time = []
for i in range(len(data)-1):
tempData.append(data[i]['temperature'])
voltData.append(data[i]['volt'])
time.append(i)
print(voltData)
print(tempData)
plt.plot(time, tempData, 'b-')
plt.plot(time, voltData, 'r-')
plt.show()
Here are the values for voltData and tempData
['3.94', '3.38', '3.85', '3.89', '3.84', '3.95', '3.85', '3.85', '3.89', '3.77', '3.84', '3.68', '3.84', '3.85', '3.83', '3.30', '3.95', '3.91', '3.85', '3.87', '3.82', '3.82', '3.87', '3.91']
['15.30', '14.90', '14.90', '15.10', '15.00', '15.10', '15.00', '15.10', '14.80', '14.60', '14.70', '14.70', '14.50', '14.40', '14.20', '14.10', '13.90', '13.60', '13.20', '12.60', '12.10', '11.80', '11.50', '11.20']
Now i doent know what went wrong but here is my Output. Thanks for your help <3
Upvotes: 0
Views: 54
Reputation: 91
Changing your loop for the code bellow you will fix the problem with data stored as string.
for i in range(len(data)-1):
tempData.append(float(data[i]['temperature']))
voltData.append(float(data[i]['volt']))
time.append(i)
But ploting the two variables together may look strange because it is in different scales (TempData between 3.3 and 3.95 and VoltData between 11.2 and 15.3). Doing that you could create graph less sensible to individual data changing.
Upvotes: 1
Reputation: 70
It looks like your data is stored as string
. You should convert them to float
.
Plus, it might help you to set the spacing between the X axis and Y axis numbers. You can check it out in the documentation how to do it.
Upvotes: 1