Python matplotlib.gridspec() Examples
The following are 30
code examples of matplotlib.gridspec().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib
, or try the search function
.
Example #1
Source File: visual_evaluation.py From UMNN with BSD 3-Clause "New" or "Revised" License | 6 votes |
def plot_images(args, x_sample, dir, file_name, size_x=3, size_y=3): fig = plt.figure(figsize=(size_x, size_y)) # fig = plt.figure(1) gs = gridspec.GridSpec(size_x, size_y) gs.update(wspace=0.05, hspace=0.05) for i, sample in enumerate(x_sample): ax = plt.subplot(gs[i]) plt.axis('off') ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_aspect('equal') sample = sample.reshape((args.input_size[0], args.input_size[1], args.input_size[2])) sample = sample.swapaxes(0, 2) sample = sample.swapaxes(0, 1) if (args.input_type == 'binary') or (args.input_type in ['multinomial'] and args.input_size[0] == 1): sample = sample[:, :, 0] plt.imshow(sample, cmap='gray', vmin=0, vmax=1) else: plt.imshow(sample) plt.savefig(dir + file_name + '.png', bbox_inches='tight') plt.close(fig)
Example #2
Source File: nupic_output.py From nupic.critic with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, *args, **kwargs): super(NuPICPlotOutput, self).__init__(*args, **kwargs) self.names = [self.name] # Turn matplotlib interactive mode on. plt.ion() self.dates = [] self.convertedDates = [] self.actualValues = [] self.predictedValues = [] self.actualLines = [] self.predictedLines = [] self.linesInitialized = False self.graphs = [] plotCount = len(self.names) plotHeight = max(plotCount * 3, 6) fig = plt.figure(figsize=(14, plotHeight)) gs = gridspec.GridSpec(plotCount, 1) for index in range(len(self.names)): self.graphs.append(fig.add_subplot(gs[index, 0])) plt.title(self.names[index]) plt.ylabel('Frequency Bucket') plt.xlabel('Seconds') plt.tight_layout()
Example #3
Source File: main.py From pytorch-spectral-normalization-gan with MIT License | 6 votes |
def evaluate(epoch): samples = generator(fixed_z).cpu().data.numpy()[:64] fig = plt.figure(figsize=(8, 8)) gs = gridspec.GridSpec(8, 8) gs.update(wspace=0.05, hspace=0.05) for i, sample in enumerate(samples): ax = plt.subplot(gs[i]) plt.axis('off') ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_aspect('equal') plt.imshow(sample.transpose((1,2,0)) * 0.5 + 0.5) if not os.path.exists('out/'): os.makedirs('out/') plt.savefig('out/{}.png'.format(str(epoch).zfill(3)), bbox_inches='tight') plt.close(fig)
Example #4
Source File: nupic_output.py From nupic.critic with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, *args, **kwargs): super(NuPICPlotOutput, self).__init__(*args, **kwargs) self.names = [self.name] # Turn matplotlib interactive mode on. plt.ion() self.dates = [] self.convertedDates = [] self.actualValues = [] self.predictedValues = [] self.actualLines = [] self.predictedLines = [] self.linesInitialized = False self.graphs = [] plotCount = len(self.names) plotHeight = max(plotCount * 3, 6) fig = plt.figure(figsize=(14, plotHeight)) gs = gridspec.GridSpec(plotCount, 1) for index in range(len(self.names)): self.graphs.append(fig.add_subplot(gs[index, 0])) plt.title(self.names[index]) plt.ylabel('Frequency Bucket') plt.xlabel('Seconds') plt.tight_layout()
Example #5
Source File: task_viz.py From taskonomy with MIT License | 6 votes |
def show_jigsaw(input_batch, perm, name): import matplotlib.gridspec as gridspec fig = plt.figure(figsize=(6, 6)) outer = gridspec.GridSpec(3, 3) outer.update(wspace=0.05, hspace=0.05) for i in range(9): img = input_batch[i, :, :, :].copy() img[0,0,0] = 1.0 img[0,1,0] = 0.0 ax = plt.subplot(outer[int(perm[i]/3),perm[i]%3]) ax.axis('off') ax.get_xaxis().set_visible(False) # this removes the ticks and numbers for x axis ax.get_yaxis().set_visible(False) # this removes the ticks and numbers for y axis ax.imshow( np.squeeze(img) ) fig.savefig(name, dpi=128, bbox_inches='tight', pad_inches=0.0) plt.close()
Example #6
Source File: vid_task_viz.py From taskonomy with MIT License | 6 votes |
def show_jigsaw(input_batch, perm, name): import matplotlib.gridspec as gridspec fig = plt.figure(figsize=(6, 6)) outer = gridspec.GridSpec(3, 3) outer.update(wspace=0.05, hspace=0.05) for i in range(9): img = input_batch[i, :, :, :].copy() img[0,0,0] = 1.0 img[0,1,0] = 0.0 ax = plt.subplot(outer[int(perm[i]/3),perm[i]%3]) ax.axis('off') ax.get_xaxis().set_visible(False) # this removes the ticks and numbers for x axis ax.get_yaxis().set_visible(False) # this removes the ticks and numbers for y axis ax.imshow( np.squeeze(img) ) fig.savefig(name, dpi=128, bbox_inches='tight', pad_inches=0.0) plt.close()
Example #7
Source File: visual_evaluation.py From sylvester-flows with MIT License | 6 votes |
def plot_images(args, x_sample, dir, file_name, size_x=3, size_y=3): fig = plt.figure(figsize=(size_x, size_y)) # fig = plt.figure(1) gs = gridspec.GridSpec(size_x, size_y) gs.update(wspace=0.05, hspace=0.05) for i, sample in enumerate(x_sample): ax = plt.subplot(gs[i]) plt.axis('off') ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_aspect('equal') sample = sample.reshape((args.input_size[0], args.input_size[1], args.input_size[2])) sample = sample.swapaxes(0, 2) sample = sample.swapaxes(0, 1) if (args.input_type == 'binary') or (args.input_type in ['multinomial'] and args.input_size[0] == 1): sample = sample[:, :, 0] plt.imshow(sample, cmap='gray', vmin=0, vmax=1) else: plt.imshow(sample) plt.savefig(dir + file_name + '.png', bbox_inches='tight') plt.close(fig)
Example #8
Source File: visual_evaluation.py From ffjord with MIT License | 6 votes |
def plot_images(args, x_sample, dir, file_name, size_x=3, size_y=3): fig = plt.figure(figsize=(size_x, size_y)) # fig = plt.figure(1) gs = gridspec.GridSpec(size_x, size_y) gs.update(wspace=0.05, hspace=0.05) for i, sample in enumerate(x_sample): ax = plt.subplot(gs[i]) plt.axis('off') ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_aspect('equal') sample = sample.reshape((args.input_size[0], args.input_size[1], args.input_size[2])) sample = sample.swapaxes(0, 2) sample = sample.swapaxes(0, 1) if (args.input_type == 'binary') or (args.input_type in ['multinomial'] and args.input_size[0] == 1): sample = sample[:, :, 0] plt.imshow(sample, cmap='gray', vmin=0, vmax=1) else: plt.imshow(sample) plt.savefig(dir + file_name + '.png', bbox_inches='tight') plt.close(fig)
Example #9
Source File: axes.py From phoebe2 with GNU General Public License v3.0 | 6 votes |
def axpos(self, axpos): if axpos is None: self._axpos = axpos return if isinstance(axpos, list) or isinstance(axpos, np.ndarray): axpos = tuple(axpos) if isinstance(axpos, tuple) and (len(axpos) == 3 or len(axpos) == 6) and np.all(isinstance(ap, int) for ap in axpos): self._axpos = axpos elif isinstance(axpos, int) and axpos >= 100 and axpos < 1000: self._axpos = (int(axpos/100), int(axpos/10 % 10), int(axpos % 10)) elif isinstance(axpos, int) and axpos >= 110011 and axpos < 999999: self._axpos = tuple([int(ap) for ap in str(axpos)]) else: raise ValueError("axpos must be of type int or tuple between 100 and 999 (subplot syntax: ncols, nrows, ind) or 110011 and 999999 (gridspec syntax: ncols, nrows, indx, indy, widthx, widthy)")
Example #10
Source File: bang.py From pyclustering with GNU General Public License v3.0 | 5 votes |
def show_blocks(directory): """! @brief Show BANG-blocks (leafs only) in data space. @details BANG-blocks represents grid that was used for clustering process. @param[in] directory (bang_directory): Directory that was created by BANG algorithm during clustering process. """ dimension = len(directory.get_data()[0]) amount_canvases = 1 if dimension > 1: amount_canvases = int(dimension * (dimension - 1) / 2) figure = plt.figure() grid_spec = gridspec.GridSpec(1, amount_canvases) pairs = list(itertools.combinations(range(dimension), 2)) if len(pairs) == 0: pairs = [(0, 0)] for index in range(amount_canvases): ax = figure.add_subplot(grid_spec[index]) bang_visualizer.__draw_blocks(ax, directory.get_leafs(), pairs[index]) bang_visualizer.__draw_two_dimension_data(ax, directory.get_data(), pairs[index]) plt.show()
Example #11
Source File: samplot.py From samplot with MIT License | 5 votes |
def create_gridspec(bams, transcript_file, annotation_files, sv_type, read_data): """Helper function for creation of a correctly-sized GridSpec instance """ # give one axis to display each sample num_ax = len(bams) # add another if we are displaying the SV if sv_type: num_ax += 1 # add another if a annotation file is given if transcript_file: num_ax += 1 if annotation_files: num_ax += len(annotation_files) # set the relative sizes for each ratios = [] if sv_type: ratios = [1] for i in range(len(bams)): ratios.append(len(read_data["all_coverages"][i]) * 3) if len(read_data["all_coverages"]) > 0: ratios[-1] = 9 if annotation_files: ratios += [0.3] * len(annotation_files) if transcript_file: ratios.append(2) return gridspec.GridSpec(num_ax, 1, height_ratios=ratios), num_ax # }}} ##Annotations/Transcript methods # {{{def get_plot_annotation_plan(ranges, annotation_file):
Example #12
Source File: plot_scan_varying_model.py From dials with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot_beam_centre(self, dat): plt.figure(figsize=(13, 10)) gs = gridspec.GridSpec(2, 1, wspace=0.4, hspace=0.6) ax = plt.subplot(gs[0, 0]) ax.ticklabel_format(useOffset=False) ymin, ymax = 0.0, 0.0 for bc in dat: plt.plot(bc["phi"], bc["beam_centre_x"]) ymin = max(ymin, min(bc["beam_centre_x"]) - 0.1) ymax = max(ymax, max(bc["beam_centre_x"]) + 0.1) plt.axis(ymin=ymin, ymax=ymax) plt.xlabel(r"rotation angle $\left(^\circ\right)$") plt.ylabel(r"angle $\left(^\circ\right)$") plt.title(r"Beam centre X (pixels)") ax = plt.subplot(gs[1, 0]) ax.ticklabel_format(useOffset=False) ymin, ymax = 0.0, 0.0 for bc in dat: plt.plot(bc["phi"], bc["beam_centre_y"]) ymin = max(ymin, min(bc["beam_centre_y"]) - 0.1) ymax = max(ymax, max(bc["beam_centre_y"]) + 0.1) plt.axis(ymin=ymin, ymax=ymax) plt.xlabel(r"rotation angle $\left(^\circ\right)$") plt.ylabel(r"angle $\left(^\circ\right)$") plt.title(r"Beam centre Y (pixels)") basename = os.path.join(self._directory, "beam_centre") fullname = basename + self._format print("Saving beam centre plot to {}".format(fullname)) plt.savefig(fullname)
Example #13
Source File: clique.py From pyclustering with GNU General Public License v3.0 | 5 votes |
def show_grid(cells, data): """! @brief Show CLIQUE blocks as a grid in data space. @details Each block contains points and according to this density is displayed. CLIQUE grid helps to visualize grid that was used for clustering process. @param[in] cells (list): List of cells that is produced by CLIQUE algorithm. @param[in] data (array_like): Input data that was used for clustering process. """ dimension = cells[0].dimensions amount_canvases = 1 if dimension > 1: amount_canvases = int(dimension * (dimension - 1) / 2) figure = plt.figure() grid_spec = gridspec.GridSpec(1, amount_canvases) pairs = list(itertools.combinations(range(dimension), 2)) if len(pairs) == 0: pairs = [(0, 0)] for index in range(amount_canvases): ax = figure.add_subplot(grid_spec[index]) clique_visualizer.__draw_cells(ax, cells, pairs[index]) clique_visualizer.__draw_two_dimension_data(ax, data, pairs[index]) plt.show()
Example #14
Source File: gridspec.py From ImageFusion with MIT License | 5 votes |
def get_topmost_subplotspec(self): 'get the topmost SubplotSpec instance associated with the subplot' gridspec = self.get_gridspec() if hasattr(gridspec, "get_topmost_subplotspec"): return gridspec.get_topmost_subplotspec() else: return self
Example #15
Source File: gridspec.py From ImageFusion with MIT License | 5 votes |
def get_position(self, fig, return_all=False): """ update the subplot position from fig.subplotpars """ gridspec = self.get_gridspec() nrows, ncols = gridspec.get_geometry() figBottoms, figTops, figLefts, figRights = \ gridspec.get_grid_positions(fig) rowNum, colNum = divmod(self.num1, ncols) figBottom = figBottoms[rowNum] figTop = figTops[rowNum] figLeft = figLefts[colNum] figRight = figRights[colNum] if self.num2 is not None: rowNum2, colNum2 = divmod(self.num2, ncols) figBottom2 = figBottoms[rowNum2] figTop2 = figTops[rowNum2] figLeft2 = figLefts[colNum2] figRight2 = figRights[colNum2] figBottom = min(figBottom, figBottom2) figLeft = min(figLeft, figLeft2) figTop = max(figTop, figTop2) figRight = max(figRight, figRight2) figbox = mtransforms.Bbox.from_extents(figLeft, figBottom, figRight, figTop) if return_all: return figbox, rowNum, colNum, nrows, ncols else: return figbox
Example #16
Source File: gridspec.py From ImageFusion with MIT License | 5 votes |
def __init__(self, gridspec, num1, num2=None): """ The subplot will occupy the num1-th cell of the given gridspec. If num2 is provided, the subplot will span between num1-th cell and num2-th cell. The index stars from 0. """ rows, cols = gridspec.get_geometry() total = rows*cols self._gridspec = gridspec self.num1 = num1 self.num2 = num2
Example #17
Source File: common.py From tf-exercise-gan with MIT License | 5 votes |
def plot(samples, figId=None, retBytes=False, shape=None): if figId is None: fig = plt.figure(figsize=(4, 4)) else: fig = plt.figure(figId, figsize=(4,4)) gs = gridspec.GridSpec(4, 4) gs.update(wspace=0.05, hspace=0.05) for i, sample in enumerate(samples): ax = plt.subplot(gs[i]) plt.axis('off') ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_aspect('equal') if shape and shape[2] == 3: rescaled = np.clip(sample, 0.0, 1.0) plt.imshow(rescaled.reshape(*shape)) else: plt.imshow(sample.reshape(28, 28), cmap='Greys_r') if retBytes: buf = io.BytesIO() plt.savefig(buf, format='png') buf.seek(0) return fig, buf return fig
Example #18
Source File: plot_scan_varying_model.py From dials with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot_orientation(self, dat): plt.figure(figsize=(13, 10)) gs = gridspec.GridSpec(3, 1, wspace=0.4, hspace=0.6) ax = plt.subplot(gs[0, 0]) ax.ticklabel_format(useOffset=False) for ori in dat: plt.plot(ori["phi"], ori["phi1"]) plt.xlabel(r"rotation angle $\left(^\circ\right)$") plt.ylabel(r"angle $\left(^\circ\right)$") plt.title(r"$\phi_1$") ax = plt.subplot(gs[1, 0]) ax.ticklabel_format(useOffset=False) for ori in dat: plt.plot(ori["phi"], ori["phi2"]) plt.xlabel(r"rotation angle $\left(^\circ\right)$") plt.ylabel(r"angle $\left(^\circ\right)$") plt.title(r"$\phi_2$") ax = plt.subplot(gs[2, 0]) ax.ticklabel_format(useOffset=False) for ori in dat: plt.plot(ori["phi"], ori["phi3"]) plt.xlabel(r"rotation angle $\left(^\circ\right)$") plt.ylabel(r"angle $\left(^\circ\right)$") plt.title(r"$\phi_3$") basename = os.path.join(self._directory, "orientation") fullname = basename + self._format print("Saving orientation plot to {}".format(fullname)) plt.savefig(fullname)
Example #19
Source File: disp.py From hart with GNU General Public License v3.0 | 5 votes |
def _tile_vertical(imgs, glimpses, boxes, n_objects, fig_size, img_size, colors): # prepare figure yy, xx = imgs.shape[0], 1 + n_objects fig_y, fig_x = fig_size img_y, img_x = img_size sy, sx = yy * img_y, n_objects + img_x gs = gridspec.GridSpec(sy, sx) fig = plt.figure(figsize=(sx * fig_x, sy * fig_y)) axes = np.empty((yy, xx), dtype=object) ii = 0 for i in xrange(yy): axes[i, 0] = plt.subplot(gs[i * img_y:(i + 1) * img_y, :img_x]) for i in xrange(yy): for j in xrange(1, xx): axes[i, j] = plt.subplot(gs[i * img_y:(i + 1) * img_y, j + img_x - 1]) # plot for r in xrange(yy): axes[r, 0].imshow(imgs[r], 'gray') for n in xrange(n_objects): for (k, v), color in izip(boxes.iteritems(), colors): y, x, h, w = boxes[k] bbox = Rectangle((x[r, n], y[r, n]), w[r, n], h[r, n], edgecolor=color, facecolor='none', label=k) axes[r, 0].add_patch(bbox) for c in xrange(1, xx): axes[r, c].imshow(glimpses[r, c - 1], 'gray') # TODO: improve len_bbox = len(boxes) if len_bbox > 1: x_offset = .25 * len_bbox axes[-1, 0].legend(bbox_to_anchor=(x_offset, -.75), ncol=len_bbox, loc='lower center') return fig, axes
Example #20
Source File: plot_output.py From nupic.critic with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, name, bins, maximize, anomaly_threshold, anomaly_trigger_count): self.name = name self.bins = bins self.anomaly_threshold = anomaly_threshold self.anomaly_trigger_count = anomaly_trigger_count # Turn matplotlib interactive mode on. plt.ion() self.seconds = [] self.bin_values = {} self.anomaly_likelihoods = {} self.bin_lines = {} self.anomaly_likelihood_lines = {} self.lines_initialized = False self._chart_highlights = [] fig = plt.figure(figsize=(16, 10)) gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1]) self._mainGraph = fig.add_subplot(gs[0, 0]) plt.title(self.name) plt.xlabel('Seconds') self._anomalyGraph = fig.add_subplot(gs[1]) plt.ylabel('Anomalies') plt.xlabel('Seconds') # Maximizes window if maximize: mng = plt.get_current_fig_manager() mng.resize(*mng.window.maxsize()) plt.tight_layout()
Example #21
Source File: gridspec.py From Computable with MIT License | 5 votes |
def get_topmost_subplotspec(self): 'get the topmost SubplotSpec instance associated with the subplot' gridspec = self.get_gridspec() if hasattr(gridspec, "get_topmost_subplotspec"): return gridspec.get_topmost_subplotspec() else: return self
Example #22
Source File: pyplot.py From Computable with MIT License | 5 votes |
def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs): """ Create a subplot in a grid. The grid is specified by *shape*, at location of *loc*, spanning *rowspan*, *colspan* cells in each direction. The index for loc is 0-based. :: subplot2grid(shape, loc, rowspan=1, colspan=1) is identical to :: gridspec=GridSpec(shape[0], shape[2]) subplotspec=gridspec.new_subplotspec(loc, rowspan, colspan) subplot(subplotspec) """ fig = gcf() s1, s2 = shape subplotspec = GridSpec(s1, s2).new_subplotspec(loc, rowspan=rowspan, colspan=colspan) a = fig.add_subplot(subplotspec, **kwargs) bbox = a.bbox byebye = [] for other in fig.axes: if other==a: continue if bbox.fully_overlaps(other.bbox): byebye.append(other) for ax in byebye: delaxes(ax) draw_if_interactive() return a
Example #23
Source File: gridspec.py From matplotlib-4-abaqus with MIT License | 5 votes |
def __init__(self, gridspec, num1, num2=None): """ The subplot will occupy the num1-th cell of the given gridspec. If num2 is provided, the subplot will span between num1-th cell and num2-th cell. The index stars from 0. """ rows, cols = gridspec.get_geometry() total = rows*cols self._gridspec = gridspec self.num1 = num1 self.num2 = num2
Example #24
Source File: gridspec.py From matplotlib-4-abaqus with MIT License | 5 votes |
def get_position(self, fig, return_all=False): """ update the subplot position from fig.subplotpars """ gridspec = self.get_gridspec() nrows, ncols = gridspec.get_geometry() figBottoms, figTops, figLefts, figRights = \ gridspec.get_grid_positions(fig) rowNum, colNum = divmod(self.num1, ncols) figBottom = figBottoms[rowNum] figTop = figTops[rowNum] figLeft = figLefts[colNum] figRight = figRights[colNum] if self.num2 is not None: rowNum2, colNum2 = divmod(self.num2, ncols) figBottom2 = figBottoms[rowNum2] figTop2 = figTops[rowNum2] figLeft2 = figLefts[colNum2] figRight2 = figRights[colNum2] figBottom = min(figBottom, figBottom2) figLeft = min(figLeft, figLeft2) figTop = max(figTop, figTop2) figRight = max(figRight, figRight2) figbox = mtransforms.Bbox.from_extents(figLeft, figBottom, figRight, figTop) if return_all: return figbox, rowNum, colNum, nrows, ncols else: return figbox
Example #25
Source File: gridspec.py From matplotlib-4-abaqus with MIT License | 5 votes |
def get_topmost_subplotspec(self): 'get the topmost SubplotSpec instance associated with the subplot' gridspec = self.get_gridspec() if hasattr(gridspec, "get_topmost_subplotspec"): return gridspec.get_topmost_subplotspec() else: return self
Example #26
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 5 votes |
def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs): """ Create a subplot in a grid. The grid is specified by *shape*, at location of *loc*, spanning *rowspan*, *colspan* cells in each direction. The index for loc is 0-based. :: subplot2grid(shape, loc, rowspan=1, colspan=1) is identical to :: gridspec=GridSpec(shape[0], shape[2]) subplotspec=gridspec.new_subplotspec(loc, rowspan, colspan) subplot(subplotspec) """ fig = gcf() s1, s2 = shape subplotspec = GridSpec(s1, s2).new_subplotspec(loc, rowspan=rowspan, colspan=colspan) a = fig.add_subplot(subplotspec, **kwargs) bbox = a.bbox byebye = [] for other in fig.axes: if other==a: continue if bbox.fully_overlaps(other.bbox): byebye.append(other) for ax in byebye: delaxes(ax) draw_if_interactive() return a
Example #27
Source File: nupic_anomaly_output.py From ecg-htm with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super(NuPICPlotOutput, self).__init__(*args, **kwargs) # Turn matplotlib interactive mode on. plt.ion() self.dates = [] self.convertedDates = [] self.value = [] self.rawValue = [] self.allValues = [] self.allRawValues = [] self.predicted = [] self.anomalyScore = [] self.anomalyLikelihood = [] self.actualLine = None self.rawLine = None self.predictedLine = None self.anomalyScoreLine = None self.anomalyLikelihoodLine = None self.linesInitialized = False self._chartHighlights = [] fig = plt.figure(figsize=(16, 10)) gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1]) self._mainGraph = fig.add_subplot(gs[0, 0]) plt.title(self.name) plt.ylabel('Value') plt.xlabel('Date') self._anomalyGraph = fig.add_subplot(gs[1]) plt.ylabel('Percentage') plt.xlabel('Date') # Maximizes window mng = plt.get_current_fig_manager() mng.resize(800, 600) plt.tight_layout()
Example #28
Source File: gridspec.py From neural-network-animation with MIT License | 5 votes |
def __init__(self, gridspec, num1, num2=None): """ The subplot will occupy the num1-th cell of the given gridspec. If num2 is provided, the subplot will span between num1-th cell and num2-th cell. The index stars from 0. """ rows, cols = gridspec.get_geometry() total = rows*cols self._gridspec = gridspec self.num1 = num1 self.num2 = num2
Example #29
Source File: gridspec.py From neural-network-animation with MIT License | 5 votes |
def get_position(self, fig, return_all=False): """ update the subplot position from fig.subplotpars """ gridspec = self.get_gridspec() nrows, ncols = gridspec.get_geometry() figBottoms, figTops, figLefts, figRights = \ gridspec.get_grid_positions(fig) rowNum, colNum = divmod(self.num1, ncols) figBottom = figBottoms[rowNum] figTop = figTops[rowNum] figLeft = figLefts[colNum] figRight = figRights[colNum] if self.num2 is not None: rowNum2, colNum2 = divmod(self.num2, ncols) figBottom2 = figBottoms[rowNum2] figTop2 = figTops[rowNum2] figLeft2 = figLefts[colNum2] figRight2 = figRights[colNum2] figBottom = min(figBottom, figBottom2) figLeft = min(figLeft, figLeft2) figTop = max(figTop, figTop2) figRight = max(figRight, figRight2) figbox = mtransforms.Bbox.from_extents(figLeft, figBottom, figRight, figTop) if return_all: return figbox, rowNum, colNum, nrows, ncols else: return figbox
Example #30
Source File: gridspec.py From neural-network-animation with MIT License | 5 votes |
def get_topmost_subplotspec(self): 'get the topmost SubplotSpec instance associated with the subplot' gridspec = self.get_gridspec() if hasattr(gridspec, "get_topmost_subplotspec"): return gridspec.get_topmost_subplotspec() else: return self