예제 #1
0
def test_plotly_plot():
    plotter.set_engine('plotly')
    plot = plotter.plot
    syst2d = syst_2d()
    syst3d = syst_3d()
    color_opts = ['black', (lambda site: site.tag[0]),
                  lambda site: (abs(site.tag[0] / 100),
                                abs(site.tag[1] / 100), 0)]
    engine = plotter.get_engine()
    with tempfile.NamedTemporaryFile('w+b', suffix=plotter_file_suffix(engine)) as out:
        out_filename = out.name
        for color in color_opts:
            for syst in (syst2d, syst3d):
                plot(syst, site_color=color, cmap='binary', file=out_filename, show=False)

        color_opts = ['black', (lambda site, site2: site.tag[0]),
                      lambda site, site2: (abs(site.tag[0] / 100),
                                           abs(site.tag[1] / 100), 0)]

        syst2d.leads = []
        plot(syst2d, file=out_filename, show=False)
        del syst2d[list(syst2d.hoppings())]
        plot(syst2d, file=out_filename, show=False)

        plot(syst3d, file=out_filename, show=False)
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            plot(syst2d.finalized(), file=out_filename, show=False)

        # test 2D projections of 3D systems
        plot(syst3d, file=out_filename, pos_transform=lambda pos: pos[:2], show=False)
예제 #2
0
def test_matplotlib_plot():

    plotter.set_engine('matplotlib')
    plot = plotter.plot
    syst2d = syst_2d()
    syst3d = syst_3d()
    color_opts = [
        'k', (lambda site: site.tag[0]), lambda site:
        (abs(site.tag[0] / 100), abs(site.tag[1] / 100), 0)
    ]
    engine = plotter.get_engine()
    with tempfile.NamedTemporaryFile(
            'w+b', suffix=plotter_file_suffix(engine)) as out:
        out_filename = out.name
        for color in color_opts:
            for syst in (syst2d, syst3d):
                fig = plot(syst,
                           site_color=color,
                           cmap='binary',
                           file=out_filename)
                if (color != 'k' and isinstance(
                        color(next(iter(syst2d.sites()))), float)):
                    assert fig.axes[0].collections[0].get_array() is not None
                assert len(fig.axes[0].collections) == 6
        color_opts = [
            'k', (lambda site, site2: site.tag[0]), lambda site, site2:
            (abs(site.tag[0] / 100), abs(site.tag[1] / 100), 0)
        ]
        for color in color_opts:
            for syst in (syst2d, syst3d):
                fig = plot(syst2d,
                           hop_color=color,
                           cmap='binary',
                           file=out_filename,
                           fig_size=(2, 10),
                           dpi=30)
                if color != 'k' and isinstance(
                        color(next(iter(syst2d.sites())), None), float):
                    assert fig.axes[0].collections[1].get_array() is not None

        assert isinstance(
            plot(syst3d, file=out_filename).axes[0], mplot3d.axes3d.Axes3D)

        syst2d.leads = []
        plot(syst2d, file=out_filename)
        del syst2d[list(syst2d.hoppings())]
        plot(syst2d, file=out_filename)

        plot(syst3d, file=out_filename)
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            plot(syst2d.finalized(), file=out_filename)

        # test 2D projections of 3D systems
        plot(syst3d, file=out_filename, pos_transform=lambda pos: pos[:2])