Last active
November 21, 2016 23:17
-
-
Save dmyersturnbull/946173a70e29060da95faf5180288ab1 to your computer and use it in GitHub Desktop.
Plot a grid of nice-looking dose-response curves.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Douglas Myers-Turnbull wrote this for the Kokel Lab, which has released it under the Apache Software License, Version 2.0 | |
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1 | |
# The list of copyright owners is unknown | |
import numpy as np | |
from matplotlib import pyplot as plt | |
import seaborn as sns | |
import matplotlib | |
import pandas as pd | |
from typing import Callable, Tuple, Dict, Optional, Union | |
def plot_dose_response(df: pd.DataFrame, | |
drug_column: str='drug name', response_column: str='response', dose_column: str='log(dose)', class_column: str='class', size: Union[str, int, float]=100, | |
n_cols: int=5, ylim: Tuple[float, float]=(0, None), horizontal_padding: float=0.1, vertical_padding: float=0.3, | |
style: str='whitegrid', font_scale: float=1.2, | |
class_to_color: Optional[Dict[str, str]]=None) -> matplotlib.figure.Figure: | |
"""Plot a grid of nice-looking dose-response curves.""" | |
sns.set(font_scale=font_scale) | |
sns.set_style(style) | |
plot = sns.FacetGrid(df, col=drug_column, col_wrap=n_cols, hue=class_column, palette=class_to_color) | |
plot.map(plt.plot, dose_column, response_column) | |
size = size if isinstance(size, float) or isinstance(size, int) else df[size] | |
plot.map(plt.scatter, dose_column, response_column, s=size) | |
plot.set(xlim=(0, None), ylim=ylim) | |
plot.set_titles(col_template="{col_name}") | |
plot.fig.subplots_adjust(wspace=horizontal_padding, hspace=vertical_padding) | |
return plot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment