Plotting growth curve using python

Data plotting can be easily done in excel. Excel is a very easy and efficient tool for calculations and plotting of biological data and most people including me prefer it. With excel one has to plot the data and do all customization each and every time for a new data set. Therefore, when it comes to plotting multiple datasets of similar nature over and over again, using a programming language is more efficient. Once a template code for a plot is ready, one can plot any number of data sets with it in a few seconds. Here we will see how to plot a simple scatter plot by taking an example of growth profile (i.e. data of time vs O.D.) of a cell culture. The reading are from three experiments. The O.D.s were taken from 0 to 6 hours at an interval of one hour.

Initially we need to import the packages we will need for plotting the data. The matplotlib package is useful for plotting the data and the pandas is useful for reading the data from excel sheet. The pandas package has functions to plot the data through matplotlib but here we will not use the pandas functions to plot our data. We will directly use the matplotlib package. Below, the pyplot domain from matplotlib is imported and is named as "plt". So, anywhere in the program, plt would mean pyplot. Similarly, the pandas package is imported as "pd". You can import and name the package/domain as you like but for consistency, the naming convention of pyplot and pandas is "plt" and "pd" repsectively. Anyways, following are the commands for importing these packages.

from matplotlib import pyplot as plt
import pandas as pd
Now we have read our data from the excel sheet. I have saved the data in excel sheet named "growth_profile.xlsx". The screenshot of the excel file is shown below.



 


Following is the code for reading the excel sheet. the "read_excel" function reads the data from excel sheet and converts into a 'pandas data-frame'. We will name this data-frame as "readings". It looks similar to the excel sheet where the data is arranged in columns. Each column is named based on the labels written in the first row of the excel sheet.

Popular posts from this blog

Principal Coordinate analysis in R and python

Principal Coordinate Analysis (PCoA) in R