Hardware Reference
In-Depth Information
representation of bird activity is a histogram showing the frequency of bird visits. Although it
is possible to produce a histogram with Microsoft Excel using the Data Analysis add-in, it is a
manual process with multiple steps.
Python can programmatically create graphs with a module called matplotlib . he numpy
module is also useful for mathematical and statistical operations. To install the modules, on
the command line type the following:
sudo apt-get install python-matplotlib python-numpy
Create a new Python ile called drawgraph.py in the same directory as analyse
BirdDataFiltered.py and enter the code in Listing 17-4.
Listing 17-4 drawgraph.py
import numpy
import matplotlib
import math
matplotlib.use('PDF')
from matplotlib import pyplot
from matplotlib.dates import DateFormatter, DayLocator,;
HourLocator
from matplotlib.dates import date2num, num2date
def plotDatehist(dates, binCount, title=None,;
intervalSize=None ):
#create histogram
(hist, bin_edges) = numpy.histogram(dates, binCount)
#calculate width of each bin
width = bin_edges[1] - bin_edges[0]
#initialise chart drawing
fig = pyplot.figure()
#create the object for the chart
ax = fig.add_subplot(111)
#draw a bar chart, starting at the first data point, data
#for bars will be held in hist variable.
#the width of the bars is the width you calculated of the
#binss. The colour of the bar will be orange
ax.bar(bin_edges[:-1], hist, width=width,;
continued
Search WWH ::




Custom Search