Python matplotlib.figure.figaspect() Examples
The following are 12
code examples of matplotlib.figure.figaspect().
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.figure
, or try the search function
.
Example #1
Source File: pyplot.py From Computable with MIT License | 5 votes |
def matshow(A, fignum=None, **kw): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. With the exception of *fignum*, keyword arguments are passed to :func:`~matplotlib.pyplot.imshow`. You may set the *origin* kwarg to "lower" if you want the first row in the array to be at the bottom instead of the top. *fignum*: [ None | integer | False ] By default, :func:`matshow` creates a new figure window with automatic numbering. If *fignum* is given as an integer, the created figure will use this figure number. Because of how :func:`matshow` tries to set the figure aspect ratio to be the one of the array, if you provide the number of an already existing figure, strange things may happen. If *fignum* is *False* or 0, a new figure window will **NOT** be created. """ A = np.asanyarray(A) if fignum is False or fignum is 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized figure fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kw) sci(im) draw_if_interactive() return im
Example #2
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 5 votes |
def matshow(A, fignum=None, **kw): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. With the exception of *fignum*, keyword arguments are passed to :func:`~matplotlib.pyplot.imshow`. You may set the *origin* kwarg to "lower" if you want the first row in the array to be at the bottom instead of the top. *fignum*: [ None | integer | False ] By default, :func:`matshow` creates a new figure window with automatic numbering. If *fignum* is given as an integer, the created figure will use this figure number. Because of how :func:`matshow` tries to set the figure aspect ratio to be the one of the array, if you provide the number of an already existing figure, strange things may happen. If *fignum* is *False* or 0, a new figure window will **NOT** be created. """ A = np.asanyarray(A) if fignum is False or fignum is 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized figure fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kw) sci(im) draw_if_interactive() return im
Example #3
Source File: pyplot.py From neural-network-animation with MIT License | 5 votes |
def matshow(A, fignum=None, **kw): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. With the exception of *fignum*, keyword arguments are passed to :func:`~matplotlib.pyplot.imshow`. You may set the *origin* kwarg to "lower" if you want the first row in the array to be at the bottom instead of the top. *fignum*: [ None | integer | False ] By default, :func:`matshow` creates a new figure window with automatic numbering. If *fignum* is given as an integer, the created figure will use this figure number. Because of how :func:`matshow` tries to set the figure aspect ratio to be the one of the array, if you provide the number of an already existing figure, strange things may happen. If *fignum* is *False* or 0, a new figure window will **NOT** be created. """ A = np.asanyarray(A) if fignum is False or fignum is 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized figure fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kw) sci(im) draw_if_interactive() return im
Example #4
Source File: scalar_sdrs.py From htmpapers with GNU Affero General Public License v3.0 | 5 votes |
def plotMatches2(listofNValues, errors, listOfScales, scaleErrors, fileName = "scalar_matches.pdf"): """ Plot two figures side by side in an aspect ratio appropriate for the paper. """ w, h = figaspect(0.4) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(w,h)) plotMatches(listofNValues, errors, fileName=None, fig=fig, ax=ax1) plotScaledMatches(listOfScales, scaleErrors, fileName=None, fig=fig, ax=ax2) plt.savefig(fileName) plt.close()
Example #5
Source File: plot_helper.py From MAST-ML with MIT License | 5 votes |
def make_fig_ax(aspect_ratio=0.5, x_align=0.65, left=0.10): """ Method to make matplotlib figure and axes objects. Using Object Oriented interface from https://matplotlib.org/gallery/api/agg_oo_sgskip.html Args: aspect_ratio: (float), aspect ratio for figure and axes creation x_align: (float), x position to draw edge of figure. Needed so can display stats alongside plot left: (float), the leftmost position to draw edge of figure Returns: fig: (matplotlib fig object), a matplotlib figure object with the specified aspect ratio ax: (matplotlib ax object), a matplotlib axes object with the specified aspect ratio """ # Set image aspect ratio: w, h = figaspect(aspect_ratio) fig = Figure(figsize=(w,h)) FigureCanvas(fig) # Set custom positioning, see this guide for more details: # https://python4astronomers.github.io/plotting/advanced.html #left = 0.10 bottom = 0.15 right = 0.01 top = 0.05 width = x_align - left - right height = 1 - bottom - top ax = fig.add_axes((left, bottom, width, height), frameon=True) fig.set_tight_layout(False) return fig, ax
Example #6
Source File: plot_helper.py From MAST-ML with MIT License | 5 votes |
def make_fig_ax_square(aspect='equal', aspect_ratio=1): """ Method to make square shaped matplotlib figure and axes objects. Using Object Oriented interface from https://matplotlib.org/gallery/api/agg_oo_sgskip.html Args: aspect: (str), 'equal' denotes x and y aspect will be equal (i.e. square) aspect_ratio: (float), aspect ratio for figure and axes creation Returns: fig: (matplotlib fig object), a matplotlib figure object with the specified aspect ratio ax: (matplotlib ax object), a matplotlib axes object with the specified aspect ratio """ # Set image aspect ratio: w, h = figaspect(aspect_ratio) fig = Figure(figsize=(w,h)) FigureCanvas(fig) ax = fig.add_subplot(111, aspect=aspect) return fig, ax
Example #7
Source File: pyplot.py From GraphicDesignPatternByPython with MIT License | 4 votes |
def matshow(A, fignum=None, **kwargs): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. Parameters ---------- A : array-like(M, N) The matrix to be displayed. fignum : None or int or False If *None*, create a new figure window with automatic numbering. If *fignum* is an integer, draw into the figure with the given number (create it if it does not exist). If 0 or *False*, use the current axes if it exists instead of creating a new figure. .. note:: Because of how `.Axes.matshow` tries to set the figure aspect ratio to be the one of the array, strange things may happen if you reuse an existing figure. Returns ------- image : `~matplotlib.image.AxesImage` Other Parameters ---------------- **kwargs : `~matplotlib.axes.Axes.imshow` arguments """ A = np.asanyarray(A) if fignum is False or fignum is 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized figure fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kwargs) sci(im) return im
Example #8
Source File: pyplot.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 4 votes |
def matshow(A, fignum=None, **kwargs): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. Parameters ---------- A : array-like(M, N) The matrix to be displayed. fignum : None or int or False If *None*, create a new figure window with automatic numbering. If a nonzero integer, draw into the figure with the given number (create it if it does not exist). If 0, use the current axes (or create one if it does not exist). .. note:: Because of how `.Axes.matshow` tries to set the figure aspect ratio to be the one of the array, strange things may happen if you reuse an existing figure. Returns ------- image : `~matplotlib.image.AxesImage` Other Parameters ---------------- **kwargs : `~matplotlib.axes.Axes.imshow` arguments """ A = np.asanyarray(A) if fignum == 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized figure fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kwargs) sci(im) return im
Example #9
Source File: pyplot.py From coffeegrindsize with MIT License | 4 votes |
def matshow(A, fignum=None, **kwargs): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. Parameters ---------- A : array-like(M, N) The matrix to be displayed. fignum : None or int or False If *None*, create a new figure window with automatic numbering. If a nonzero integer, draw into the figure with the given number (create it if it does not exist). If 0, use the current axes (or create one if it does not exist). .. note:: Because of how `.Axes.matshow` tries to set the figure aspect ratio to be the one of the array, strange things may happen if you reuse an existing figure. Returns ------- image : `~matplotlib.image.AxesImage` Other Parameters ---------------- **kwargs : `~matplotlib.axes.Axes.imshow` arguments """ A = np.asanyarray(A) if fignum == 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized figure fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kwargs) sci(im) return im
Example #10
Source File: plot_helper.py From MAST-ML with MIT License | 4 votes |
def plot_3d_heatmap(xs, ys, zs, heats, savepath, xlabel='x', ylabel='y', zlabel='z', heatlabel='heat'): """ Method to plot a heatmap for values of three variables; used for plotting GridSearch results in hyperparameter optimization. Args: xs: (numpy array), array of first variable values to plot heatmap against ys: (numpy array), array of second variable values to plot heatmap against zs: (numpy array), array of third variable values to plot heatmap against heats: (numpy array), array of heat values to plot savepath: (str), path to save the 2D heatmap to xlabel: (str), the x-axis label ylabel: (str), the y-axis label zlabel: (str), the z-axis label heatlabel: (str), the heat value axis label """ # Escape from error of passing tuples when optimzing neural net # TODO have more general solution try: # this import has side effects, needed for 3d plots: from mpl_toolkits.mplot3d import Axes3D # Set image aspect ratio: # (eeds to be wide enough or plot will shrink really skinny) w, h = figaspect(0.6) fig = Figure(figsize=(w,h)) FigureCanvas(fig) # modifies fig in place ax = fig.add_subplot(111, projection='3d') scat = ax.scatter(xs, ys, zs, c=heats) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) ax.set_zlabel(zlabel) cb = fig.colorbar(scat) cb.set_label(heatlabel) fig.savefig(savepath, dpi=DPI, bbox_inches='tight') except TypeError: pass def animate(i): ax.view_init(elev=10., azim=i) return [fig] anim = FuncAnimation(fig, animate, frames=range(0,90,5), blit=True) #anim.save(savepath+'.mp4', fps=5, extra_args=['-vcodec', 'libx264']) anim.save(savepath+'.gif', fps=5, dpi=80, writer='imagemagick')
Example #11
Source File: pyplot.py From CogAlg with MIT License | 4 votes |
def matshow(A, fignum=None, **kwargs): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. Parameters ---------- A : array-like(M, N) The matrix to be displayed. fignum : None or int or False If *None*, create a new figure window with automatic numbering. If a nonzero integer, draw into the figure with the given number (create it if it does not exist). If 0, use the current axes (or create one if it does not exist). .. note:: Because of how `.Axes.matshow` tries to set the figure aspect ratio to be the one of the array, strange things may happen if you reuse an existing figure. Returns ------- image : `~matplotlib.image.AxesImage` Other Parameters ---------------- **kwargs : `~matplotlib.axes.Axes.imshow` arguments """ A = np.asanyarray(A) if fignum == 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized # figure. fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kwargs) sci(im) return im
Example #12
Source File: pyplot.py From twitter-stock-recommendation with MIT License | 4 votes |
def matshow(A, fignum=None, **kwargs): """ Display an array as a matrix in a new figure window. The origin is set at the upper left hand corner and rows (first dimension of the array) are displayed horizontally. The aspect ratio of the figure window is that of the array, unless this would make an excessively short or narrow figure. Tick labels for the xaxis are placed on top. Parameters ---------- A : array-like(M, N) The matrix to be displayed. fignum : None or int or False If *None*, create a new figure window with automatic numbering. If *fignum* is an integer, draw into the figure with the given number (create it if it does not exist). If 0 or *False*, use the current axes if it exists instead of creating a new figure. .. note:: Because of how `.Axes.matshow` tries to set the figure aspect ratio to be the one of the array, strange things may happen if you reuse an existing figure. Returns ------- image : `~matplotlib.image.AxesImage` Other Parameters ---------------- **kwargs : `~matplotlib.axes.Axes.imshow` arguments """ A = np.asanyarray(A) if fignum is False or fignum is 0: ax = gca() else: # Extract actual aspect ratio of array and make appropriately sized figure fig = figure(fignum, figsize=figaspect(A)) ax = fig.add_axes([0.15, 0.09, 0.775, 0.775]) im = ax.matshow(A, **kwargs) sci(im) return im