Current section
Files
Jump to
Current section
Files
priv/jun_seaborn.py
#!/usr/bin/env python# -*- coding: utf-8 -*-import sysimport scipy as spimport numpy as npimport matplotlib as mplimport pandas as pdimport sklearn as sklmpl.use('Agg')import seaborn as sns# common helper for dataframe plot using seaborn,# trying to return a file instead a raw opaque itemdef jun_dataframe_plot(df, fn, save='None', keywords=[]): if ( isinstance(df, pd.core.frame.DataFrame) ): # clean before any plot mpl.pyplot.figure() # make dict from keywords even if empty! kwargs = dict(keywords) # get the fun from seaborn directly since we want a dynamic call fun = getattr(sns, fn) plot = fun(**kwargs) if ( plot.__class__.__name__ == 'AxesSubplot' ): plot_class = 'matplotlib.AxesSubplot' else: plot_class = 'seaborn.axisgrid.*' if save != 'None': # if figure comes from seaborn use fig, otherwise get_figure if ( plot_class == 'matplotlib.AxesSubplot' ): fig = plot.get_figure() else: fig = plot.fig fig.savefig(save, bbox_inches='tight') # save contains path return plot_class else: return (plot_class, plot) # this is correct? because can be confusing with opaque df else: return 'error_format_data_frame_invalid'