Skip to content

Instantly share code, notes, and snippets.

@fomightez
Last active February 18, 2020 22:34
Show Gist options
  • Save fomightez/7f445311a78484c83c3210cbd5540192 to your computer and use it in GitHub Desktop.
Save fomightez/7f445311a78484c83c3210cbd5540192 to your computer and use it in GitHub Desktop.
plotly plot for standard curve of yeast growth that is part of cell density estimator
# PASTE ALL OF THIS IN A CELL IN THE NOTEBOOK AT https://github.com/fomightez/methods_in_yeast_genetics/blob/master/cell_density_estimator/cell_density_estimator_for_multiple_samples.ipynb
# and then run after running the code above. IN FACT IT IS NOW ADDED TO THE NOTEBOOK!
import plotly.graph_objects as go
import pandas as pd
od660_values_list, cells_per_ml_values_list = unzip(yeast_cell_density_by_OD660_tuples)
cells_per_ml_values_list = [(x/1.0e7) for x in cells_per_ml_values_list] # trying to get them in scale, see http://stackoverflow.com/questions/32542957/control-tick-labels-in-python-seaborn-package
data_dict = {'od':od660_values_list, 'cells_per_ml':cells_per_ml_values_list} # see http://www.gregreda.com/2013/10/26/intro-to-pandas-data-structures/
data_df = pd.DataFrame(data_dict,columns=['od','cells_per_ml']) # see http://www.gregreda.com/2013/10/26/intro-to-pandas-data-structures/
data = [
go.Scatter(
x=data_df['cells_per_ml'], # assign x as the dataframe column 'x'
y=data_df['od']
)
]
layout = go.Layout(
title='Optical Density vs. Cell Density',
xaxis=dict(
title='$\\text{cells per ml (}\\times 10^7{)}$' #latex help from https://plot.ly/python/LaTeX/
),
yaxis=dict(
title='$\\text{OD}_{660}$'
)
)
# IPython notebook
pfig=go.Figure(data=data,layout=layout)
pfig.show()
##BELOW IS OLD 2016 CODE BEFORE IT WORKS RIGHT IN JUPYTER WITHOUT CREDENTIALS #########################
'''
# PASTE ALL OF THIS IN A CELL IN THE NOTEBOOK AT https://github.com/fomightez/methods_in_yeast_genetics/blob/master/cell_density_estimator/cell_density_estimator_for_multiple_samples.ipynb AND
# THEN EDIT TO INCLUDE YOUR PLOTLY CREDENTIALS.
import plotly
import plotly.plotly as py
py.sign_in('YOUR_PLOTLY_USERNAME', 'YOUR_PLOTLY_API_KEY')
import plotly.graph_objs as go
# based on example at https://plot.ly/pandas/line-charts/
import pandas as pd
od660_values_list, cells_per_ml_values_list = unzip(yeast_cell_density_by_OD660_tuples)
cells_per_ml_values_list = [(x/1.0e7) for x in cells_per_ml_values_list] # trying to get them in scale, see http://stackoverflow.com/questions/32542957/control-tick-labels-in-python-seaborn-package
data_dict = {'od':od660_values_list, 'cells_per_ml':cells_per_ml_values_list} # see http://www.gregreda.com/2013/10/26/intro-to-pandas-data-structures/
data_df = pd.DataFrame(data_dict,columns=['od','cells_per_ml']) # see http://www.gregreda.com/2013/10/26/intro-to-pandas-data-structures/
data = [
go.Scatter(
x=data_df['cells_per_ml'], # assign x as the dataframe column 'x'
y=data_df['od']
)
]
layout = go.Layout(
title='Optical Density vs. Cell Density',
xaxis=dict(
title='$\\text{cells per ml (}\\times 10^7{)}$' #latex help from https://plot.ly/python/LaTeX/
),
yaxis=dict(
title='$\\text{OD}_{660}$'
)
)
# IPython notebook
figure=go.Figure(data=data,layout=layout) # this and next line from https://plot.ly/python/user-guide/ , under 'What is Plotly?' since differs from basic example above in that need layout pointed to.
py.iplot(figure, filename='od_vs_cell_density')
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment