def show(self, axis=None): if axis is None: axis = plt if self.item_type == 'line': c = self.item_colors if not c: c = 'w' if len(self.x) > 0: plot = axis.plot(arr(self.x).flatten(), arr(self.y).flatten(), c=c) else: plot = axis.plot(arr(self.y).flatten(), c=c) elif self.item_type == 'scatter': plot = axis.scatter(self.x, self.y, color=self.item_colors) elif self.item_type == 'bar': plot = axis.bar( self.x, self.y, tick_label=self.xticklabels, width=PLT_BAR_W, align='center', color=self.item_colors ) elif self.item_type == 'box': plot = axis.boxplot( self.y, positions=self.x, showmeans=True, labels=self.xticklabels, # NOT WORKING widths=PLT_BAR_W, boxprops={'color': self.item_colors}, flierprops={'markerfacecolor': self.item_colors}, capprops={'color': self.item_colors}, whiskerprops={'color': self.item_colors}, manage_ticks=False ) axis.set_xticklabels(self.xticklabels) axis.set_xticks(self.x) axis.set_title(self.title) if isreal(self.minX) and isreal(self.maxX): axis.set_xlim([self.minX, self.maxX]) if isreal(self.minY) and isreal(self.maxY): axis.set_ylim([self.minY, self.maxY]) axis.set_ylabel(self.y_label) axis.set_xlabel(self.x_label) if self.hideYTicks: axis.set_yticks([]) if self.tickFont is not None: axis.set_xticklabels(axis.get_xticklabels(), self.tickFont) axis.set_yticklabels(axis.get_yticklabels(), self.tickFont) if self.legend: axis.legend( handles=self.legend, loc='lower left' ) assert axis != plt
def bar(cls, fd): from matplotlib import pyplot as plt # 1 FULL SECOND IMPORT maxY = None if fd.maxY is None or fd.maxY == 'inf' or not isreal( fd.maxY) else float(fd.maxY) minY = None if fd.minY is None or fd.minY == 'inf' or not isreal( fd.minY) else float(fd.minY) # maxX = None if fd.maxX is None or fd.maxX == '-inf' or not isreal(fd.maxX) else float(fd.maxX) # minX = None if fd.minX is None or fd.minX == 'inf' or not isreal(fd.minX) else float(fd.minX) if maxY != None and minY != None: diff = maxY - minY pad = diff * (fd.y_pad_percent / 100) maxY = maxY + pad minY = minY - pad if cls.fig is None: if BLACK_FIGS: cls.fig = plt.figure(figsize=(16, 12), facecolor='black') cls.ax = cls.fig.add_subplot(111, facecolor='black') else: cls.fig = plt.figure(figsize=(16, 12)) cls.ax = cls.fig.add_subplot(111) cls.ax.bar(fd.x, fd.y, color=listmap(cls.color, fd.item_colors), yerr=fd.err) title_obj = cls.ax.set_title(fd.title, fontsize=fd.title_size) plt.setp(title_obj, color=text_color) cls.ax.axis(True) cls.ax.spines['left'].set_color(text_color) cls.ax.spines['bottom'].set_color(text_color) cls.ax.xaxis.label.set_color(text_color) cls.ax.yaxis.label.set_color(text_color) cls.ax.tick_params(axis='x', colors=text_color) cls.ax.tick_params(axis='y', colors=text_color)
def defaultPlotOptions(fd): maxY = wl.All if fd.maxY is None or fd.maxY == 'inf' or not isreal( fd.maxY) else float(fd.maxY) minY = wl.All if fd.minY is None or fd.minY == 'inf' or not isreal( fd.minY) else float(fd.minY) maxX = wl.All if fd.maxX is None or fd.maxX == '-inf' or not isreal( fd.maxX) else float(fd.maxX) minX = wl.All if fd.minX is None or fd.minX == 'inf' or not isreal( fd.minX) else float(fd.minX) if maxY != wl.All and minY != wl.All: diff = maxY - minY pad = diff * (fd.y_pad_percent / 100) maxY = maxY + pad minY = minY - pad if maxX != wl.All and minX != wl.All: # forced padding for labels diff = maxX - minX pad = diff * 0.2 maxX = maxX + pad return [ PlotLabel(Style(fd.title, FontSize(fd.title_size))), PlotRange([[minX, maxX], [minY, maxY]]), LabelStyle(bgi), Background(bg), FrameTicksStyle(Directive(bgi, 10)), AxesStyle(Directive(Large, bgi)), IntervalMarkersStyle(bgi), # (* {{Large, bgi}, {Large, bgi}}*) Frame(True), FrameStyle([ [ # left Directive(Opacity(1), FontOpacity(1), FontSize(fd.label_size)), # right Directive(Opacity(0), FontOpacity(1), FontSize(fd.label_size)) ], [ # bottom Directive(Opacity(1), FontOpacity(1), FontSize(fd.label_size)), # top Directive(Opacity(0), FontOpacity(1), FontSize(fd.label_size)) ] ]), LabelStyle([bgi, FontWeight("Bold"), FontSize(fd.label_size)]) ]
def violin(cls, fd): from matplotlib import pyplot as plt # 1 FULL SECOND IMPORT maxY = None if fd.maxY is None or fd.maxY == 'inf' or not isreal( fd.maxY) else float(fd.maxY) minY = None if fd.minY is None or fd.minY == 'inf' or not isreal( fd.minY) else float(fd.minY) if maxY != None and minY != None: diff = maxY - minY pad = diff * (fd.y_pad_percent / 100) maxY = maxY + pad minY = minY - pad if cls.fig is None: if BLACK_FIGS: cls.fig = plt.figure(figsize=(16, 12), facecolor='black') cls.ax = cls.fig.add_subplot(111, facecolor='black') else: cls.fig = plt.figure(figsize=(16, 12)) cls.ax = cls.fig.add_subplot(111) try: cls.ax.violinplot(fd.y, showmeans=True) except FloatingPointError as e: # weird underflow error if str(e) == 'underflow encountered in exp': progress( 'funny violinplot error occurred again. rebuild locally') cls.ax.plot([1, 2, 3]) return else: import traceback traceback.print_exc() breakpoint() x = range(1, len(fd.x) + 1) cls.ax.set_xticks(x) cls.ax.set_xticklabels(fd.x) # fd.x, title_obj = cls.ax.set_title(fd.title, fontsize=fd.title_size) plt.setp(title_obj, color=text_color) cls.ax.axis(True) cls.ax.spines['left'].set_color(text_color) cls.ax.spines['bottom'].set_color(text_color) cls.ax.xaxis.label.set_color(text_color) cls.ax.yaxis.label.set_color(text_color) cls.ax.tick_params(axis='x', colors=text_color) cls.ax.tick_params(axis='y', colors=text_color) cls.ax.set_ylabel(fd.y_label) cls.ax.set_xlabel(fd.x_label) drawn_xs = [] drawn_ys = [] def will_overlap(wbx, wby): for iii in itr(drawn_xs): twbx = drawn_xs[iii] twby = drawn_ys[iii] if ((min(wbx) <= min(twbx)) and (max(wbx) >= min(twbx))) or ((max(wbx) >= max(twbx)) and (min(wbx) <= max(twbx))): # x overlaps if ((min(wby) <= min(twby)) and (max(wby) >= min(twby))) or ((max(wby) >= max(twby)) and (min(wby) <= max(twby))): return True # return True return False from scipy import stats the_y = [np.mean(it) for it in fd.y] for i in itr(fd.y): for ii in itr(fd.y): if i <= ii: continue # breakpoint() dh = .05 # default, barh = .05 # default will_be_y1 = max(the_y[i], the_y[ii]) + dh will_be_y2 = will_be_y1 + barh will_be_x = [i, ii] will_be_y = [will_be_y1, will_be_y2] while will_overlap(will_be_x, will_be_y): dh += .05 will_be_y1 = max(the_y[i], the_y[ii]) + dh will_be_y2 = will_be_y1 + barh will_be_x = [i, ii] will_be_y = [will_be_y1, will_be_y2] drawn_xs.append(will_be_x) drawn_ys.append(will_be_y) cls.barplot_annotate_brackets( i, ii, stats.ttest_ind(fd.y[i], fd.y[ii], alternative='two-sided')[1], x, # list(itr(fd.y)), #fd.x the_y, dh=dh, barh=barh) @classmethod def bar(cls, fd): from matplotlib import pyplot as plt # 1 FULL SECOND IMPORT maxY = None if fd.maxY is None or fd.maxY == 'inf' or not isreal( fd.maxY) else float(fd.maxY) minY = None if fd.minY is None or fd.minY == 'inf' or not isreal( fd.minY) else float(fd.minY) # maxX = None if fd.maxX is None or fd.maxX == '-inf' or not isreal(fd.maxX) else float(fd.maxX) # minX = None if fd.minX is None or fd.minX == 'inf' or not isreal(fd.minX) else float(fd.minX) if maxY != None and minY != None: diff = maxY - minY pad = diff * (fd.y_pad_percent / 100) maxY = maxY + pad minY = minY - pad if cls.fig is None: if BLACK_FIGS: cls.fig = plt.figure(figsize=(16, 12), facecolor='black') cls.ax = cls.fig.add_subplot(111, facecolor='black') else: cls.fig = plt.figure(figsize=(16, 12)) cls.ax = cls.fig.add_subplot(111) cls.ax.bar(fd.x, fd.y, color=listmap(cls.color, fd.item_colors), yerr=fd.err) title_obj = cls.ax.set_title(fd.title, fontsize=fd.title_size) plt.setp(title_obj, color=text_color) cls.ax.axis(True) cls.ax.spines['left'].set_color(text_color) cls.ax.spines['bottom'].set_color(text_color) cls.ax.xaxis.label.set_color(text_color) cls.ax.yaxis.label.set_color(text_color) cls.ax.tick_params(axis='x', colors=text_color) cls.ax.tick_params(axis='y', colors=text_color) @classmethod def none(cls): pass @classmethod def color(cls, *rgb): rgb = arr(rgb) * 128 # if len(rgb.shape) == 3: # if rgb.shape[0] == 1: # rgb = rgb[0] return '#%02x%02x%02x' % tuple(ints(rgb).tolist()) @classmethod @abstractmethod def tableItem(cls, o, background): err('unused')
def line(cls, fd): from matplotlib import pyplot as plt # 1 FULL SECOND IMPORT maxY = None if fd.maxY is None or fd.maxY == 'inf' or not isreal( fd.maxY) else float(fd.maxY) minY = None if fd.minY is None or fd.minY == 'inf' or not isreal( fd.minY) else float(fd.minY) maxX = None if fd.maxX is None or fd.maxX == '-inf' or not isreal( fd.maxX) else float(fd.maxX) minX = None if fd.minX is None or fd.minX == 'inf' or not isreal( fd.minX) else float(fd.minX) if maxY != None and minY != None: diff = maxY - minY pad = diff * (fd.y_pad_percent / 100) maxY = maxY + pad minY = minY - pad if maxX != None and minX != None: # forced padding for labels diff = maxX - minX pad = diff * 0.2 maxX = maxX + pad # callouts (fd.callout_x) (fd.callout) if cls.fig is None: if BLACK_FIGS: cls.fig = plt.figure(figsize=(16, 12), facecolor='black') else: cls.fig = plt.figure(figsize=(16, 12)) if BLACK_FIGS: cls.ax = cls.fig.add_subplot(111, facecolor='black') else: cls.ax = cls.fig.add_subplot(111) cls.ax.plot(fd.x, fd.y, color=cls.color(fd.item_colors)) cls.ax.set_ylim(bottom=minY, top=maxY) cls.ax.set_xlim(left=minX, right=maxX) title_obj = cls.ax.set_title(fd.title, fontsize=fd.title_size) plt.setp(title_obj, color=text_color) cls.ax.axis(True) cls.ax.spines['left'].set_color(text_color) cls.ax.spines['bottom'].set_color(text_color) cls.ax.xaxis.label.set_color(text_color) cls.ax.yaxis.label.set_color(text_color) cls.ax.tick_params(axis='x', colors=text_color) cls.ax.tick_params(axis='y', colors=text_color) # cls.ax.set_xticks(li(xt_mpl_t) * gl) # cls.ax.set_xticklabels(xt_mpl_l, rotation=90) # cls.ax.xticks(rotation=90) # cls.ax.set_yticks(li(yt_mpl_t) * gl) # cls.ax.set_yticklabels(yt_mpl_l) cls.ax.annotate( # fd.callout, # "some text", fd.y_label, xy=(fd.x[-1], fd.y[-1]), xytext=((fd.x[-1] * 1.035), fd.y[-1]), xycoords='data', horizontalalignment='left', verticalalignment='bottom', fontsize=20, arrowprops=dict(facecolor='w', shrink=0.05), bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3))