def main(self, parent): if parent==None: return self.parent = parent self._doFrame() self.setDefaultStyle() grps = {'formats':['kind','wrap','palette','logy','aspect'], 'factors':['hue','col','x','ci','melt'], 'labels':['title','ylabel','rot','fontscale']} self.groups = grps = OrderedDict(grps) styles = ['darkgrid', 'whitegrid', 'dark', 'white', 'ticks'] kinds = ['point', 'bar', 'count', 'box', 'violin', 'strip'] palettes = ['Spectral','cubehelix','hls','hot','coolwarm','copper', 'winter','spring','summer','autumn','Greys','Blues','Reds', 'Set1','Set2','Accent'] datacols = [] self.opts = {'wrap': {'type':'entry','default':2,'label':'column wrap'}, 'palette': {'type':'combobox','default':'Spectral','items':palettes}, 'kind': {'type':'combobox','default':'bar','items':kinds}, 'col': {'type':'combobox','default':'','items':datacols}, 'hue': {'type':'combobox','default':'','items':datacols}, 'x': {'type':'combobox','default':'','items':datacols}, 'ci':{'type':'entry','default':95,'width':16}, 'melt':{'type':'checkbutton','default':1,'label':'convert to long form'}, 'fontscale':{'type':'scale','default':1.2,'range':(.5,3),'interval':.1,'label':'font scale'}, 'title':{'type':'entry','default':'','width':16}, 'ylabel':{'type':'entry','default':'','width':16}, 'rot':{'type':'entry','default':0, 'label':'xlabel angle'}, 'logy':{'type':'checkbutton','default':0,'label':'log y'}, 'aspect':{'type':'entry','default':1.0, 'label':'aspect'}, } fr = self._plotWidgets(self.mainwin) fr.pack(side=LEFT,fill=BOTH) bf = Frame(self.mainwin, padding=2) bf.pack(side=LEFT,fill=BOTH) b = Button(bf, text="Replot", command=self._plot) b.pack(side=TOP,fill=X,pady=2) b = Button(bf, text="Clear", command=self.clear) b.pack(side=TOP,fill=X,pady=2) b = Button(bf, text="Close", command=self.quit) b.pack(side=TOP,fill=X,pady=2) b = Button(bf, text="About", command=self._aboutWindow) b.pack(side=TOP,fill=X,pady=2) self.table = self.parent.getCurrentTable() df = self.table.model.df self.update(df) sheet = self.parent.getCurrentSheet() #reference to parent frame in sheet pw = self.parent.sheetframes[sheet] #hide the plot viewer from the sheet? #self.parent.hidePlot() self.pf = Frame(pw) pw.add(self.pf, weight=3) self.fig, self.canvas = plotting.addFigure(self.pf) return
def _plot(self): """Do plot""" import seaborn as sns self.applyOptions() kwds = self.kwds fontscale = kwds['fontscale'] font = kwds['font'] self.setDefaultStyle(fontscale=fontscale, font=font) df = self.table.getPlotData() #dtypes = list(df.dtypes) col = kwds['col'] wrap=int(kwds['wrap']) ci = kwds['ci'] logy = kwds['logy'] melt = kwds['melt'] if col == '': col = None wrap = 1 if wrap == 1: row=col col=None wrap=None else: row=None hue = kwds['hue'] kind = kwds['kind'] x = kwds['x'] order = None if x == '': x = 'var' aspect = float(kwds['aspect']) palette=kwds['palette'] xlabelrot = kwds['rot'] if hue == '': hue=None if col == '': col=None labels = list(df.select_dtypes(include=['object','category']).columns) if melt == True: t = pd.melt(df,id_vars=labels, var_name='var',value_name='value') else: t = df try: g = sns.factorplot(x=x,y='value',data=t, hue=hue, col=col, row=row, col_wrap=wrap, kind=kind,size=3, aspect=float(aspect), legend_out=False, sharey='all', palette=palette, order=order, ci=ci) self.g = g except Exception as e: self.showWarning(e) return #need to always make a new canvas to get size right for child in self.pf.winfo_children(): child.destroy() self.fig, self.canvas = plotting.addFigure(self.pf, g.fig) plt.suptitle(kwds['title'], fontsize=14*fontscale) plt.legend(loc='best') ylabel = kwds['ylabel'] for ax in g.axes.flatten(): for t in ax.get_xticklabels(): t.set(rotation=xlabelrot) if ylabel != '': ax.set_ylabel(ylabel) if logy == True: ax.set_yscale('log') plt.tight_layout() bottom = 0.1 if xlabelrot>30: bottom=0.2 self.fig.subplots_adjust(top=0.9, bottom=bottom) self.canvas.draw() return