Skip to content

Instantly share code, notes, and snippets.

@mdekstrand
Created September 17, 2020 22:36
Show Gist options
  • Save mdekstrand/2559219aacee9b9fd659b46d43d4498c to your computer and use it in GitHub Desktop.
Save mdekstrand/2559219aacee9b9fd659b46d43d4498c to your computer and use it in GitHub Desktop.
def make_plot(data, aes, *args, file=None, height=5, width=7, theme=theme_paper(), **kwargs):
plt = pn.ggplot(data, aes)
for a in args:
plt = plt + a
plt = plt + theme + pn.theme(**kwargs)
if file is not None:
outf = _fig_dir / file
if outf.suffix:
warnings.warn('file has suffix, ignoring')
plt.save(outf.with_suffix('.pdf'), height=height, width=width)
plt.save(outf.with_suffix('.png'), height=height, width=width, dpi=300)
return plt
make_polt = function(plot, file=NA, width=5, height=3, ...) {
if (!is.na(file)) {
png(paste(file, "png", sep="."), width=width, height=height, units='in', res=600, ...)
print(plot)
dev.off()
cairo_pdf(paste(file, "pdf", sep="."), width=width, height=height, ...)
print(plot)
dev.off()
}
plot
}
class theme_paper(pn.theme_minimal):
def __init__(self):
pn.theme_minimal.__init__(self, base_family='Open Sans')
self.add_theme(pn.theme(
axis_title=pn.element_text(size=10),
axis_title_y=pn.element_text(margin={'r': 12}),
panel_border=pn.element_rect(color='gainsboro', size=1, fill=None)
), inplace=True)
theme_paper = function() {
# theme_minimal(base_size=10, base_family='Source Sans Pro') +
theme_minimal(base_size=10) +
theme(panel.border=element_rect(linetype="solid", color="grey", fill=NA),
plot.margin=margin())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment