0

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

2
  • 1
    Your data are strings, convert them to floats. Commented Apr 27, 2021 at 18:56
  • While I get you're trying to get help with your code, copying and pasting your code and asking why it is broken isn't super helpful others in the future. Instead try asking a more generic question and provide concrete code examples of what's not working. Commented Apr 27, 2021 at 20:54

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.