Gigabyte2
Posts: 94
Joined: Thu Jan 31, 2013 9:15 pm

Temperature and hours daily plotting

Wed Apr 23, 2014 1:28 pm

Hi, I have written a Python program for controlling a peppers greenhouse.
The program reads temperature and humidity from a sensors but now I want to create a plot with these values.
How I can generate a simple plot with 24 hours range?

Thank you ;)

User avatar
DougieLawson
Posts: 37070
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Temperature and hours daily plotting

Wed Apr 23, 2014 1:53 pm

sudo apt-get install python{,3}-matplotlib

Code: Select all

#!/usr/bin/python3

import matplotlib.pyplot as pyplot

labels = ['04:00', '05:00', '06:00', '07:00']
x = [0.1667, 0.2083, 0.2500, 0.2916]
y = [12, 13, 14.5, 17.3]

pyplot.plot(x,y)
pyplot.show()
I'll leave it for you to add the labels to the x-axis.

There's a get started guide at: http://www.ucs.cam.ac.uk/docs/course-no ... graphs.pdf
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Temperature and hours daily plotting

Wed Apr 23, 2014 2:01 pm

Weird. I've just written a blog post on plotting data from a sensor log using gnuplot. Dougie's answer if probably best if you want to keep it all within Python.

gnuplot is quite handy when you are experimenting but you need the data in a separate text file.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

User avatar
DougieLawson
Posts: 37070
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Temperature and hours daily plotting

Wed Apr 23, 2014 2:16 pm

MattHawkinsUK wrote: Dougie's answer if probably best if you want to keep it all within Python.
I assumed that since the question appeared in the Python sub-forum.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
DougieLawson
Posts: 37070
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Temperature and hours daily plotting

Wed Apr 23, 2014 2:18 pm

MattHawkinsUK wrote:Weird. I've just written a blog post on plotting data from a sensor log using gnuplot.
Thanks for sharing a well written article with pretty examples.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: Temperature and hours daily plotting

Wed Apr 23, 2014 3:10 pm

If you're in web pages, I suggest jqplot.

Go here (http://cupidcontrol.com/mobile/dataviewer.html) enter viewer/viewer, toggle the log button, and hit refresh plot to see what this looks like.

Colin
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Re: Temperature and hours daily plotting

Wed Apr 23, 2014 8:54 pm

There are loads of good examples of plotting graphs already mentioned in this post. I have a couple of blog posts which show how to plot graphs from within Python which are very easy to do.

http://trevorappleton.blogspot.co.uk/se ... bel/Graphs
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

Return to “Python”