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


Python pylab.switch_backend函数代码示例

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


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

示例1: test_plot_functions

def test_plot_functions():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    data = np.zeros((20, 20, 20))
    data[3:-3, 3:-3, 3:-3] = 1
    img = nibabel.Nifti1Image(data, mni_affine)
    ortho_slicer = plot_anat(img, dim=True)
    # Test saving with empty plot
    z_slicer = plot_anat(anat_img=False, display_mode='z')
    ortho_slicer.savefig(tempfile.TemporaryFile())
    z_slicer = plot_anat(display_mode='z')
    ortho_slicer.savefig(tempfile.TemporaryFile())
    z_slicer.add_edges(img, color='c')

    for func in [plot_anat, plot_img, plot_stat_map,
                 plot_epi, plot_glass_brain]:
        ortho_slicer = func(img, cut_coords=(80, -120, -60))
        # Saving forces a draw, and thus smoke-tests the axes locators
        ortho_slicer.savefig(tempfile.TemporaryFile())
        ortho_slicer.add_edges(img, color='c')

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

        out = func(img, output_file=tempfile.TemporaryFile(suffix='.png'))
        assert_true(out is None)
    pl.close('all')
开发者ID:ofercoq,项目名称:nilearn,代码行数:32,代码来源:test_img_plotting.py

示例2: reason_pylab

def reason_pylab():
    from .utils import deliver_image
    def _canvas_deliver(canvas):
        tf = tempfile.TemporaryFile()
        canvas.print_png(tf)
        tf.seek(0)
        img_data = base64.b64encode(tf.read())
        tf.close()
        deliver_image(img_data)
    def reason_draw_if_interactive():
        if matplotlib.is_interactive():
            figManager =  Gcf.get_active()
            if figManager is not None:
                _canvas_deliver(figManager.canvas)
    def reason_show(mainloop = True):
        # We ignore mainloop here
        for manager in Gcf.get_all_fig_managers():
            _canvas_deliver(manager.canvas)
    # Matplotlib has very nice backend overriding.
    # We should really use that.  This is just a hack.
    import matplotlib
    matplotlib.use("agg") # Hotfix for when we import pylab below
    new_agg = imp.new_module("reason_agg")
    import matplotlib.backends.backend_agg as bagg
    new_agg.__dict__.update(bagg.__dict__)
    new_agg.__dict__.update(
        {'show': reason_show,
         'draw_if_interactive': reason_draw_if_interactive})
    sys.modules["reason_agg"] = new_agg
    bagg.draw_if_interactive = reason_draw_if_interactive
    from matplotlib._pylab_helpers import Gcf
    matplotlib.rcParams["backend"] = "module://reason_agg"
    import pylab
    pylab.switch_backend("module://reason_agg")
开发者ID:danielgrassinger,项目名称:yt_new_frontend,代码行数:34,代码来源:extdirect_repl.py

示例3: test_demo_plot_map

def test_demo_plot_map():
    # This is only a smoke test
    mp.use("svg", warn=False)
    import pylab as pl

    pl.switch_backend("svg")
    demo_plot_map()
开发者ID:neurospin,项目名称:nipy,代码行数:7,代码来源:test_activation_maps.py

示例4: test_plot_anat

def test_plot_anat():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    data = np.zeros((20, 20, 20))
    data[3:-3, 3:-3, 3:-3] = 1
    img = nibabel.Nifti1Image(data, mni_affine)
    ortho_slicer = plot_anat(img, dim=True)
    ortho_slicer = plot_anat(img, cut_coords=(80, -120, -60))
    # Saving forces a draw, and thus smoke-tests the axes locators
    pl.savefig(tempfile.TemporaryFile())
    ortho_slicer.edge_map(img, color='c')

    # Test saving with empty plot
    z_slicer = plot_anat(anat_img=False, slicer='z')
    pl.savefig(tempfile.TemporaryFile())
    z_slicer = plot_anat(slicer='z')
    pl.savefig(tempfile.TemporaryFile())
    z_slicer.edge_map(img, color='c')
    # Smoke test coordinate finder, with and without mask
    masked_img = nibabel.Nifti1Image(np.ma.masked_equal(data, 0),
                                     mni_affine)
    plot_img(masked_img, slicer='x')
    plot_img(img, slicer='y')
开发者ID:VirgileFritsch,项目名称:nilearn,代码行数:25,代码来源:test_img_plotting.py

示例5: test_replace_inside

def test_replace_inside():
    # This is only a smoke test
    mp.use("svg", warn=False)
    import pylab as pl

    pl.switch_backend("svg")
    replace_inside(pl.cm.jet, pl.cm.hsv, 0.2, 0.8)
开发者ID:schwarty,项目名称:nipy,代码行数:7,代码来源:test_cm.py

示例6: test_replace_inside

def test_replace_inside():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    replace_inside(pl.cm.jet, pl.cm.hsv, .2, .8)
    # We also test with gnuplot, which is defined using function
    replace_inside(pl.cm.gnuplot, pl.cm.gnuplot2, .2, .8)
开发者ID:FNNDSC,项目名称:nipy,代码行数:8,代码来源:test_cm.py

示例7: test_demo_plot_map

def test_demo_plot_map():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    demo_plot_map()
    # Test the black background code path
    demo_plot_map(black_bg=True)
开发者ID:VirgileFritsch,项目名称:nipy,代码行数:8,代码来源:test_activation_maps.py

示例8: test_plot_map_with_auto_cut_coords

def test_plot_map_with_auto_cut_coords():
    import pylab as pl
    pl.switch_backend('svg')
    data = np.zeros((20, 20, 20))
    data[3:-3, 3:-3, 3:-3] = 1

    for slicer in 'xyz':
        plot_map(data, np.eye(4), cut_coords=None, slicer=slicer,
                 black_bg=True)
开发者ID:Naereen,项目名称:nipy,代码行数:9,代码来源:test_activation_maps.py

示例9: test_plot_anat

def test_plot_anat():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    ortho_slicer = plot_anat()
    data = np.zeros((100, 100, 100))
    data[3:-3, 3:-3, 3:-3] = 1
    ortho_slicer.edge_map(data, mni_sform, color='c')
开发者ID:Hiccup,项目名称:nipy,代码行数:9,代码来源:test_activation_maps.py

示例10: test_demo_ortho_slicer

def test_demo_ortho_slicer():
    # This is only a smoke test
    # conditioned on presence of MNI templated
    if not find_mni_template():
        raise nose.SkipTest("MNI Template is absent for the smoke test")
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    demo_ortho_slicer()
开发者ID:Hiccup,项目名称:nipy,代码行数:9,代码来源:test_ortho_slicer.py

示例11: test_plot_img_with_auto_cut_coords

def test_plot_img_with_auto_cut_coords():
    import pylab as pl
    pl.switch_backend('svg')
    data = np.zeros((20, 20, 20))
    data[3:-3, 3:-3, 3:-3] = 1
    img = nibabel.Nifti1Image(data, np.eye(4))

    for slicer in 'xyz':
        plot_img(img, cut_coords=None, slicer=slicer, black_bg=True)
开发者ID:VirgileFritsch,项目名称:nilearn,代码行数:9,代码来源:test_img_plotting.py

示例12: test_demo_ortho_slicer

def test_demo_ortho_slicer():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    pl.clf()
    oslicer = OrthoSlicer(cut_coords=(0, 0, 0))
    img = load_mni152_template()
    oslicer.add_overlay(img, cmap=pl.cm.gray)
    oslicer.close()
开发者ID:abenicho,项目名称:nilearn,代码行数:10,代码来源:test_slicers.py

示例13: test_demo_plot_roi

def test_demo_plot_roi():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    demo_plot_roi()
    # Test the black background code path
    demo_plot_roi(black_bg=True)

    out = demo_plot_roi(output_file=tempfile.TemporaryFile(suffix='.png'))
    assert_true(out is None)
开发者ID:ofercoq,项目名称:nilearn,代码行数:11,代码来源:test_img_plotting.py

示例14: test_demo_ortho_projector

def test_demo_ortho_projector():
    # This is only a smoke test
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    pl.clf()
    img = load_mni152_template()
    oprojector = OrthoProjector.init_with_figure(img=img)
    oprojector.add_overlay(img, cmap=pl.cm.gray)
    oprojector.savefig(tempfile.TemporaryFile())
    oprojector.close()
开发者ID:ofercoq,项目名称:nilearn,代码行数:11,代码来源:test_displays.py

示例15: test_stacked_slicer

def test_stacked_slicer():
    # Test stacked slicers, like the XSlicer
    mp.use('svg', warn=False)
    import pylab as pl
    pl.switch_backend('svg')
    pl.clf()
    img = load_mni152_template()
    slicer = XSlicer.init_with_figure(img=img, cut_coords=3)
    slicer.add_overlay(img, cmap=pl.cm.gray)
    # Forcing a layout here, to test the locator code
    slicer.savefig(tempfile.TemporaryFile())
    slicer.close()
开发者ID:abenicho,项目名称:nilearn,代码行数:12,代码来源:test_slicers.py


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