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


Python pyplot.close函数代码示例

本文整理汇总了Python中matplotlib.pyplot.close函数的典型用法代码示例。如果您正苦于以下问题:Python close函数的具体用法?Python close怎么用?Python close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_radardisplay_init

def test_radardisplay_init():
    # test that a display object can be created with and without
    radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
    radar.antenna_transition = {'data': np.zeros((40, ))}
    display = pyart.graph.RadarDisplay(radar)
    assert display.antenna_transition is not None
    plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:7,代码来源:test_radardisplay.py

示例2: scree_plot

def scree_plot(pca_obj, fname=None): 
    '''
    Scree plot for variance & cumulative variance by component from PCA. 

    Arguments: 
        - pca_obj: a fitted sklearn PCA instance
        - fname: path to write plot to file

    Output: 
        - scree plot 
    '''   
    components = pca_obj.n_components_ 
    variance = pca.explained_variance_ratio_
    plt.figure()
    plt.plot(np.arange(1, components + 1), np.cumsum(variance), label='Cumulative Variance')
    plt.plot(np.arange(1, components + 1), variance, label='Variance')
    plt.xlim([0.8, components]); plt.ylim([0.0, 1.01])
    plt.xlabel('No. Components', labelpad=11); plt.ylabel('Variance Explained', labelpad=11)
    plt.legend(loc='best') 
    plt.tight_layout() 
    if fname is not None:
        plt.savefig(fname)
        plt.close() 
    else:
        plt.show() 
    return 
开发者ID:thomasbrawner,项目名称:python_tools,代码行数:26,代码来源:scree_plot.py

示例3: display_d3

def display_d3(fig=None, closefig=True, d3_url=None):
    """Display figure in IPython notebook via the HTML display hook

    Parameters
    ----------
    fig : matplotlib figure
        The figure to display (grabs current figure if missing)
    closefig : boolean (default: True)
        If true, close the figure so that the IPython matplotlib mode will not
        display the png version of the figure.
    d3_url : string (optional)
        The URL of the d3 library.  If not specified, a standard web path
        will be used.

    Returns
    -------
    fig_d3 : IPython.display.HTML object
        the IPython HTML rich display of the figure.

    See Also
    --------
    show_d3 : show a figure in a new browser window, notebook not required.
    enable_notebook : automatically embed figures in the IPython notebook
    """
    # import here, in case users don't have requirements installed
    from IPython.display import HTML
    import matplotlib.pyplot as plt
    if fig is None:
        fig = plt.gcf()
    if closefig:
        plt.close(fig)
    return HTML(fig_to_d3(fig, d3_url=d3_url))
开发者ID:catarinacavaco,项目名称:mpld3,代码行数:32,代码来源:display.py

示例4: graph_view

def graph_view(request):
    try:
        fig = plot.figure()
        ax = fig.add_subplot(111)
        plot_data(request, ax, 0)
        plot_data(request, ax, 1)
        ax.set_xlabel("Time")
        ax.set_ylabel(u"Temperature (°C)")
        fig.autofmt_xdate()
        imgdata = StringIO.StringIO()
        fig.savefig(imgdata, format='svg')
        return Response(imgdata.getvalue(), content_type='image/svg+xml')
    except DBAPIError:
        conn_err_msg = """\
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="10cm" height="10cm" viewBox="0 0 100 300"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
  <desc>Database connection error message</desc>
  <text x="0" y="0" fill="red">Database error.</text>
  </svg>"""
        return Response(conn_err_msg, content_type='image/svg+xml', status_int=500)
    finally:
        plot.close('all')
开发者ID:bwduncan,项目名称:autoboiler,代码行数:25,代码来源:views.py

示例5: make_iso_visual_panel

def make_iso_visual_panel(fn, img_compo, img_map, contours1, contours3, z, pixsize, legend_suffix, name, title_compo, title_map, label_cbar):
    fig, (ax0, ax1, ax_cb) = get_figure_grids(n_panel=2)

    # plot composit
    ax_imshow(fig, ax0, img_compo, origin='upper', tocolorbar=False, tosetlim=True)

    nx, ny = img_compo.shape[:2]
    overplot_ruler(ax0, z, pixsize=pixsize, rlength_arcsec=10., nx=nx, ny=ny)

    ax0.text(5, 12, name, color='white', fontsize=12)
    ax0.text(nx-35, 12, '$z={}$'.format('%.2f'%z), color='white', fontsize=10)
    ax0.set_title(title_compo)
    ax0.title.set_position([.5, 1.03])

    # plot line map
    im = ax_imshow(fig, ax1, img_map, vmin=-1, vmax=8, origin='lower', tocolorbar=False, tosetlim=True)
    overplot_contours(ax1, contours3, lw=1.)
    overplot_contours(ax1, contours1, lw=0.2)

    make_legend_isophotes(ax1, lw=2, suffix=legend_suffix)

    ax1.set_title(title_map)
    ax1.title.set_position([.5, 1.03])

    # plot color bar
    cbar = fig.colorbar(im, cax=ax_cb, label=label_cbar, format='%i')
    ax_cb.set_aspect(20)

    # set ticks off
    for ax in [ax0, ax1]: 
        ax.axis('off')

    # saving
    fig.savefig(fn, format='pdf')
    plt.close()
开发者ID:aileisun,项目名称:bubblepy,代码行数:35,代码来源:plottools.py

示例6: plot_cc

    def plot_cc(self):
        with PdfPages("CCplot.pdf") as pdf:
            for each_frame in self.frame_list:
                fig, axs = plt.subplots(5,5, sharex=True, sharey=True, squeeze=True, facecolor='w', edgecolor='k')
                fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1, hspace = 0.5, wspace=0.1)

                fig.text(0.5, 0.04, 'CCweak', ha='center')
                fig.text(0.04, 0.5, 'CCall', va='center', rotation='vertical')
                fig.set_size_inches(8,11)

                axs = axs.flatten()

                for i in range(len(each_frame)):
                   ccall, ccweak = get_CCs(each_frame[i])
                   if len(ccweak) > len(ccall):
                     diff = len(ccweak) - len(ccall)
                     axs[i].plot(ccweak[0:(len(ccweak)-diff)], ccall, 'o', linewidth=1, rasterized=True)
                   elif len(ccweak) < len(ccall):
                      diff = len(ccall) - len(ccweak)
                      axs[i].plot(ccweak, ccall[0:(len(ccall)-diff)], 'o', linewidth=1, rasterized=True)
                   else:
                      axs[i].plot(ccweak, ccall, 'o', linewidth=1, rasterized=True)

                   titles = each_frame[i].strip('-shelxd.log')
                   axs[i].set_title(titles, fontsize=8)
                pdf.savefig(fig)
                plt.close()
开发者ID:shibom,项目名称:scripts_sls,代码行数:27,代码来源:plot_cluster.py

示例7: export

def export(data, F, k):
    '''Write data to a png image
    
    Arguments
    ---------
    data : numpy.ndarray
        array containing the data to be written as png image
    F : float
        feed rate of the current configuration
    k : float
        rate constant of the current configuration
    '''
        
    figsize = tuple(s / 72.0 for s in data.shape)
    fig = plt.figure(figsize=figsize, dpi=72.0, facecolor='white')
    fig.add_axes([0, 0, 1, 1], frameon=False)
    plt.xticks([])
    plt.yticks([])

    plt.imshow(data, cmap=plt.cm.RdBu_r, interpolation='bicubic')
    plt.gci().set_clim(0, 1)

    filename = './study/F{:03d}-k{:03d}.png'.format(int(1000*F), int(1000*k))
    plt.savefig(filename, dpi=72.0)
    plt.close()
开发者ID:michaelschaefer,项目名称:grayscott,代码行数:25,代码来源:parameterstudy.py

示例8: test_singleton_ax_dim

def test_singleton_ax_dim():
    for axis, direction in enumerate("xyz"):
        shape = [5, 6, 7]
        shape[axis] = 1
        img = nibabel.Nifti1Image(np.ones(shape), np.eye(4))
        plot_stat_map(img, None, display_mode=direction)
        plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:7,代码来源:test_img_plotting.py

示例9: test_plot_anat

def test_plot_anat():
    img = _generate_img()

    # Test saving with empty plot
    z_slicer = plot_anat(anat_img=False, display_mode='z')
    filename = tempfile.mktemp(suffix='.png')
    try:
        z_slicer.savefig(filename)
    finally:
        os.remove(filename)

    z_slicer = plot_anat(display_mode='z')
    filename = tempfile.mktemp(suffix='.png')
    try:
        z_slicer.savefig(filename)
    finally:
        os.remove(filename)

    ortho_slicer = plot_anat(img, dim='auto')
    filename = tempfile.mktemp(suffix='.png')
    try:
        ortho_slicer.savefig(filename)
    finally:
        os.remove(filename)

    # Save execution time and memory
    plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:27,代码来源:test_img_plotting.py

示例10: test_radardisplay_get_colorbar_label

def test_radardisplay_get_colorbar_label():
    radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
    display = pyart.graph.RadarDisplay(radar)

    # default is to base the label on the standard_name key
    assert (display._get_colorbar_label('reflectivity_horizontal') ==
            'equivalent reflectivity factor (dBZ)')

    # next is to look at the long_name
    del display.fields['reflectivity_horizontal']['standard_name']
    assert (display._get_colorbar_label('reflectivity_horizontal') ==
            'Reflectivity (dBZ)')

    # use the field if standard_name and long_name missing
    del display.fields['reflectivity_horizontal']['long_name']
    print(display._get_colorbar_label('reflectivity_horizontal'))
    assert (display._get_colorbar_label('reflectivity_horizontal') ==
            'reflectivity horizontal (dBZ)')

    # no units if key is missing
    del display.fields['reflectivity_horizontal']['units']
    print(display._get_colorbar_label('reflectivity_horizontal'))
    assert (display._get_colorbar_label('reflectivity_horizontal') ==
            'reflectivity horizontal (?)')
    plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:25,代码来源:test_radardisplay.py

示例11: test_plot_stat_map

def test_plot_stat_map():
    img = _generate_img()

    plot_stat_map(img, cut_coords=(80, -120, -60))

    # Smoke test coordinate finder, with and without mask
    masked_img = nibabel.Nifti1Image(
        np.ma.masked_equal(img.get_data(), 0),
        mni_affine)
    plot_stat_map(masked_img, display_mode='x')
    plot_stat_map(img, display_mode='y', cut_coords=2)

    # 'yx' display_mode
    plot_stat_map(img, display_mode='yx')

    # regression test #510
    data = np.zeros((91, 109, 91))
    aff = np.eye(4)
    new_img = nibabel.Nifti1Image(data, aff)
    plot_stat_map(new_img, threshold=1000, colorbar=True)

    rng = np.random.RandomState(42)
    data = rng.randn(91, 109, 91)
    new_img = nibabel.Nifti1Image(data, aff)
    plot_stat_map(new_img, threshold=1000, colorbar=True)

    # Save execution time and memory
    plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:28,代码来源:test_img_plotting.py

示例12: test_radardisplay_misc

def test_radardisplay_misc():
    # misc methods which are not tested above
    radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
    display = pyart.graph.RadarDisplay(radar)
    fig = plt.figure()
    ax = fig.add_subplot(111)

    # _set_vpt_title with a title
    display._set_vpt_title('foo_field', 'title_string', ax)
    assert ax.get_title() == 'title_string'

    # _generate_field_name method
    fn = pyart.graph.common.generate_field_name(
        radar, 'reflectivity_horizontal')
    assert fn == 'Equivalent reflectivity factor'

    display.fields['reflectivity_horizontal'].pop('standard_name')
    fn = pyart.graph.common.generate_field_name(
        radar, 'reflectivity_horizontal')
    assert fn == 'Reflectivity'

    display.fields['reflectivity_horizontal'].pop('long_name')
    fn = pyart.graph.common.generate_field_name(
        radar, 'reflectivity_horizontal')
    assert fn == 'Reflectivity horizontal'

    plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:27,代码来源:test_radardisplay.py

示例13: test_radardisplay_user_specified_labels

def test_radardisplay_user_specified_labels():
    # test that labels are set when a user specifies them.
    radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_PPI_FILE)
    display = pyart.graph.RadarDisplay(radar)
    fig = plt.figure()
    ax = fig.add_subplot(111)

    display._set_ray_title('field', 0, 'foo', ax)
    assert ax.get_title() == 'foo'

    display._label_axes_ppi(('foo', 'bar'), ax)
    assert ax.get_xlabel() == 'foo'
    assert ax.get_ylabel() == 'bar'

    display._label_axes_rhi(('spam', 'eggs'), ax)
    assert ax.get_xlabel() == 'spam'
    assert ax.get_ylabel() == 'eggs'

    display._label_axes_ray(('baz', 'qux'), 'field', ax)
    assert ax.get_xlabel() == 'baz'
    assert ax.get_ylabel() == 'qux'

    display._label_axes_vpt(('nick', 'nock'), False, ax)
    assert ax.get_xlabel() == 'nick'
    assert ax.get_ylabel() == 'nock'
    plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:26,代码来源:test_radardisplay.py

示例14: test_radardisplay_plot_rhi_reverse

def test_radardisplay_plot_rhi_reverse():
    radar = pyart.io.read_cfradial(pyart.testing.CFRADIAL_RHI_FILE)
    display = pyart.graph.RadarDisplay(radar)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    display.plot('reflectivity_horizontal', 0, ax=ax, reverse_xaxis=True)
    plt.close()
开发者ID:gavi,项目名称:pyart,代码行数:7,代码来源:test_radardisplay.py

示例15: test_heatmap_ticklabel_rotation

    def test_heatmap_ticklabel_rotation(self):

        f, ax = plt.subplots(figsize=(2, 2))
        mat.heatmap(self.df_norm, ax=ax)

        for t in ax.get_xticklabels():
            nt.assert_equal(t.get_rotation(), 0)

        for t in ax.get_yticklabels():
            nt.assert_equal(t.get_rotation(), 90)

        plt.close(f)

        df = self.df_norm.copy()
        df.columns = [str(c) * 10 for c in df.columns]
        df.index = [i * 10 for i in df.index]

        f, ax = plt.subplots(figsize=(2, 2))
        mat.heatmap(df, ax=ax)

        for t in ax.get_xticklabels():
            nt.assert_equal(t.get_rotation(), 90)

        for t in ax.get_yticklabels():
            nt.assert_equal(t.get_rotation(), 0)

        plt.close(f)
开发者ID:petebachant,项目名称:seaborn,代码行数:27,代码来源:test_matrix.py


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