当前位置: 首页>>代码示例>>Python>>正文


Python figure.figaspect方法代码示例

本文整理汇总了Python中matplotlib.figure.figaspect方法的典型用法代码示例。如果您正苦于以下问题:Python figure.figaspect方法的具体用法?Python figure.figaspect怎么用?Python figure.figaspect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.figure的用法示例。


在下文中一共展示了figure.figaspect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: matshow

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:42,代码来源:pyplot.py

示例2: plotMatches2

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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() 
开发者ID:numenta,项目名称:htmpapers,代码行数:16,代码来源:scalar_sdrs.py

示例3: make_fig_ax

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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 
开发者ID:uw-cmg,项目名称:MAST-ML,代码行数:38,代码来源:plot_helper.py

示例4: make_fig_ax_square

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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 
开发者ID:uw-cmg,项目名称:MAST-ML,代码行数:28,代码来源:plot_helper.py

示例5: matshow

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:54,代码来源:pyplot.py

示例6: matshow

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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 
开发者ID:holzschu,项目名称:python3_ios,代码行数:52,代码来源:pyplot.py

示例7: plot_3d_heatmap

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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') 
开发者ID:uw-cmg,项目名称:MAST-ML,代码行数:57,代码来源:plot_helper.py

示例8: matshow

# 需要导入模块: from matplotlib import figure [as 别名]
# 或者: from matplotlib.figure import figaspect [as 别名]
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 
开发者ID:boris-kz,项目名称:CogAlg,代码行数:52,代码来源:pyplot.py


注:本文中的matplotlib.figure.figaspect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。