Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – plotting experimental data


Now that we've defined the relationship between the optical density and the concentration of bacteria, let's look at a series of data points taken over the span of an hour. We will convert from optical density to concentration units, and plot the data.

sample_times = numpy.array([0, 20, 40, 60, 80, 100, 120, 
    140, 160, 180, 200, 220, 240, 280, 360, 380, 400, 420,
    440, 460, 500, 520, 540, 560, 580, 600, 620, 640, 660,
    680, 700, 720, 760, 1240, 1440, 1460, 1500, 1560])

OD_readings = numpy.array([0.083, 0.087, 0.116, 0.119, 0.122,
    0.123, 0.125, 0.131, 0.138, 0.142, 0.158, 0.177, 0.213,
    0.234, 0.424, 0.604, 0.674, 0.726, 0.758, 0.828, 0.919, 
    0.996, 1.024, 1.066, 1.092, 1.107, 1.113, 1.116, 1.12, 
    1.129, 1.132, 1.135, 1.141, 1.109, 1.004, 0.984, 0.972, 0.952])

concentrations = standard_curve(OD_readings, std_params[slope],
     std_params[intercept])
exp_data = zip(sample_times, concentrations)

data_plot = scatter_plot(exp_data, markersize=20, facecolor='red', 
    axes_labels=['time (sec)', 'CFU/ml'])
show(data_plot)

The scatter plot looks like this:

What just happened?

We defined one NumPy array of sample times, and another NumPy array of optical density values. As in the previous example, these values could easily be read from a file. We used the standard_curve function and the fitted parameter values from the previous example to convert the optical density to concentration. We then plotted the data points using the scatter_plot function.