def __init__( self, dims, suffix, data_exists, is_table=False, rows=None, cols=None ): self.data_exists = data_exists self.dims = dims self.row_headers = None self.col_headers = None if dims == 1: self.data = arr2d() elif dims == 2: if isinstance(self, FinalResult): self.data = np.zeros((len(rows), len(cols), 1)) self.row_headers = make2d([None] + rows).T self.col_headers = make2d([None] + cols) else: self.data = arr3d() self.suffix = StringExtension(suffix) self.j = None self.is_table = is_table
def add_headers_to_mat(ar2d, row_headers, col_headers, alphabetize=False): ar2d = np.concatenate((make2d(col_headers), arr(ar2d)), axis=0) row_headers = make2d(np.insert(row_headers, 0, None)).T cmat = np.concatenate((row_headers, ar2d), axis=1) if alphabetize: cmat[1:] = sort_human(cmat[1:]) temp = np.transpose(arr(cmat)) temp[1:] = sort_human(temp[1:]) cmat = np.transpose(arr(temp)) return cmat
def append(self, exp_data, indices, is_GNET=False): if self.dims == 1: row = exp_data.y if is_GNET: row = np.mean(np.reshape(arr(row), (-1, 3)), axis=1).tolist() self.data = vert(self.data, row) elif self.dims == 2: data = arr(exp_data.data) if self.is_table: data = arr(exp_data.data, dtype=np.object) self.row_headers = make2d(data[:, 0]).T self.col_headers = make2d(data[0, :]) data = arr(data[1:, 1:], dtype=float) self.data = lay(self.data, data)
def makefig( subplots, file=None, show=False, width=6, height=8 ): assert subplots is not None if not isitr(subplots): subplots = [[subplots]] subplots = arr(subplots, ndims=2) from matplotlib import rcParams rcParams['figure.figsize'] = width, height rcParams["savefig.dpi"] = 200 with plt.style.context('dark_background'): # if len(subplots.shape) != 2: if len(subplots.shape) == 1: ncol = 1 else: ncol = subplots.shape[1] nrow = subplots.shape[0] subplots = make2d(subplots) fig, axs = plt.subplots(ncols=ncol, nrows=nrow, squeeze=False) if len(axs.shape) == 1: # noinspection PyUnresolvedReferences axs.shape = (axs.shape[0], 1) for r, row in enumerate(subplots): for c, fd in enumerate(row): if isinstance(fd, MultiPlot): [d.show(axs[r, c]) for d in fd] else: fd.show(axs[r, c]) fig.tight_layout(pad=3.0) if file is None: plt.show() else: File(file).mkparents() plt.savefig(file) plt.clf() if show: showInPreview(imageFile=File(file).abspath) return File(file)
def addHeaderLabels(mat, top, side): data = objarray(mat, 2) # noinspection PyTypeChecker data = concat( make2d([ None, Item( Text(side, fontSize=30, direction=ROTATE_90 # direction=[0,1] )) ] + ((np.repeat([SpanFromAbove], len(data) - 2).tolist()) if len(data) > 2 else [])).T, data, axis=1) # noinspection PyTypeChecker data = np.insert( data, 0, [None, None, Item(Text(top, fontSize=30))] + ((np.repeat([SpanFromLeft], len(data[0]) - 3).tolist()) if len(data[0]) > 2 else []), axis=0) return data