Skip to content

Instantly share code, notes, and snippets.

@dmyersturnbull
Last active November 21, 2016 23:20
Show Gist options
  • Save dmyersturnbull/f13b89afbe7f2340c08877ac32fd3f60 to your computer and use it in GitHub Desktop.
Save dmyersturnbull/f13b89afbe7f2340c08877ac32fd3f60 to your computer and use it in GitHub Desktop.
Plot something the way I prefer it.
# 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
from typing import Callable, Optional, Tuple, Iterable
from matplotlib.axes import SubplotBase
import seaborn as sns
def prettify_plot(plot_fn: Callable[[], SubplotBase],
style :str='whitegrid',
bounds: Tuple[int, int]=(40, 20), font_scale: float=3,
x_lim: Optional[Tuple[Optional[float], Optional[float]]]=None,
y_lim: Optional[Tuple[Optional[float], Optional[float]]]=None,
x_ticks: Optional[Iterable[float]]=None,
y_ticks: Optional[Iterable[float]]=None) -> SubplotBase:
"""Plot something the same I prefer it. Matplotlib determines values if they're passed as None."""
sns.set(rc={'figure.figsize': bounds}, font_scale=font_scale)
sns.set_style(style)
plot = plot_fn()
if x_lim is not None:
plot.set(xlim=x_lim)
if y_lim is not None:
plot.set(ylim=y_lim)
if x_ticks is not None:
plot.axes.set_xticks(x_ticks)
if y_ticks is not None:
plot.axes.set_xticks(y_ticks)
return plot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment