Created
August 9, 2019 13:20
-
-
Save trainorpj/4005744c9d139a04e9531a444838cbe3 to your computer and use it in GitHub Desktop.
matplotlib utilities for better plotting
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
# copy/paste everything below here | |
# -------------------------------- | |
import matplotlib.pyplot as plt | |
# ggplot styles | |
plt.style.use('ggplot') | |
# ggplot first six default colors | |
_gg_colors = ["#F8766D", "#B79F00", "#00BA38", "#00BFC4", "#619CFF", "#F564E3"] | |
_gg_red, _gg_yellow, _gg_green, _gg_teal, _gg_blue, _gg_pink = _gg_colors | |
# plot title based on axis call | |
def _plot_title_axis_handler(title, ax=None, **kwargs): | |
if ax is None: | |
plt.title(title, **kwargs) | |
else: | |
ax.set_title(title, **kwargs) | |
# left/right (i.e. main/subtitle) titles | |
# using keyword arguments will override the defaults | |
def plt_left_title(title, ax=None, **kwargs): _plot_title_axis_handler(title, ax=ax, **{**dict(loc="left", fontsize=18), **kwargs}) | |
def plt_right_title(title, ax=None, **kwargs): _plot_title_axis_handler(title, ax=ax, **{**dict(loc="right", color="grey", fontsize=13), **kwargs}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment