Esempio n. 1
0
def get_fig_2d():
    fig = plt.figure()
    ax = fig.add_subplot(111)
    try:
        yield fig, ax
    finally:
        plt.close(fig)
Esempio n. 2
0
def get_fig_3d():
    fig = plt.figure()
    ax = fig.add_subplot((111), projection='3d')
    try:
        yield fig, ax
    finally:
        plt.close(fig)
Esempio n. 3
0
def test_save_plot():
    with tempfile.TemporaryDirectory() as folder:
        fig_old = plt.figure()
        output_path = Path(folder, 'subdir')
        fig = save_plot(fig_old, output_path=output_path)
        assert Path(output_path, 'Figure.png').is_file()
        plt.close('all')
Esempio n. 4
0
def get_fig_3d():
    fig = plt.figure()
    ax = fig.add_subplot((111), projection='3d')
    try:
        yield fig, ax
    finally:
        plt.close(fig)
Esempio n. 5
0
def get_fig_2d():
    fig = plt.figure()
    ax = fig.add_subplot(111)
    try:
        yield fig, ax
    finally:
        plt.close(fig)
Esempio n. 6
0
def test_save_plot():
    if os.path.isfile(fig_name):
        os.remove(fig_name)
    fig_old = plt.figure()
    fig = save_plot(fig_old)
    nt.ok_(os.path.isfile(fig_name) == True)
    os.remove(fig_name)
    if os.path.isdir(fig_dir):
        for data in os.listdir(fig_dir):
            os.remove(fig_dir + data)
        os.rmdir(fig_dir)
    fig = save_plot(fig_old, output_path=fig_dir)
    nt.ok_(os.path.isfile(fig_dir + fig_name) == True)
    os.remove(fig_dir + fig_name)
    os.rmdir(fig_dir)
    plt.close('all')
Esempio n. 7
0
def test_save_plot():
    if os.path.isfile(fig_name):
        os.remove(fig_name)
    fig_old = plt.figure()
    fig = save_plot(fig_old)
    nt.ok_(os.path.isfile(fig_name)==True)
    os.remove(fig_name)
    if os.path.isdir(fig_dir):
        for data in os.listdir(fig_dir):
            os.remove(fig_dir + data)
        os.rmdir(fig_dir)
    fig = save_plot(fig_old, output_path=fig_dir)
    nt.ok_(os.path.isfile(fig_dir + fig_name)==True)
    os.remove(fig_dir + fig_name)
    os.rmdir(fig_dir)
    plt.close('all')
Esempio n. 8
0
def test_save_plot():
    fig_name = 'Figure.png'

    tempdir = tempfile.mkdtemp('test_common')
    try:
        old_dir = os.getcwd()
        os.chdir(tempdir)

        fig_old = plt.figure()
        fig = save_plot(fig_old)
        nt.ok_(os.path.isfile(fig_name))

        os.remove(fig_name)

        fig = save_plot(fig_old, output_path='subdir')
        nt.ok_(os.path.isfile(os.path.join(tempdir, 'subdir', fig_name)))
    finally:
        os.chdir(old_dir)
        shutil.rmtree(tempdir)
        plt.close('all')
Esempio n. 9
0
def test_save_plot():
    fig_name = 'Figure.png'

    tempdir = tempfile.mkdtemp('test_common')
    try:
        old_dir = os.getcwd()
        os.chdir(tempdir)

        fig_old = plt.figure()
        fig = save_plot(fig_old)
        nt.ok_(os.path.isfile(fig_name))

        os.remove(fig_name)

        fig = save_plot(fig_old, output_path='subdir')
        nt.ok_(os.path.isfile(os.path.join(tempdir, 'subdir', fig_name)))
    finally:
        os.chdir(old_dir)
        shutil.rmtree(tempdir)
        plt.close('all')
Esempio n. 10
0
def test_get_figure():
    fig_old = plt.figure()
    fig, ax = get_figure(new_fig=False, subplot=False)
    nt.ok_(fig == fig_old)
    nt.ok_(ax.colNum == 0)
    nt.ok_(ax.rowNum == 0)
    fig1, ax1 = get_figure(new_fig=True, subplot=224)
    nt.ok_(fig1 != fig_old)
    nt.ok_(ax1.colNum == 1)
    nt.ok_(ax1.rowNum == 1)
    fig = get_figure(new_fig=True, no_axes=True)
    nt.ok_(type(fig) == plt.Figure)
    fig2, ax2 = get_figure(new_fig=True, subplot=[1, 1, 1])
    nt.ok_(ax2.colNum == 0)
    nt.ok_(ax2.rowNum == 0)
    plt.close('all')
    fig = plt.figure()
    ax = fig.add_subplot(111)
    fig2, ax2 = get_figure(new_fig=False, new_axes=False)
    nt.ok_(fig2 == plt.gcf())
    nt.ok_(ax2 == plt.gca())
    plt.close('all')
Esempio n. 11
0
def test_get_figure():
    fig_old = plt.figure()
    fig, ax = get_figure(new_fig=False, subplot=False)
    nt.ok_(fig == fig_old)
    nt.ok_(ax.colNum == 0)
    nt.ok_(ax.rowNum == 0)
    fig1, ax1 = get_figure(new_fig=True, subplot=224)
    nt.ok_(fig1 != fig_old)
    nt.ok_(ax1.colNum == 1)
    nt.ok_(ax1.rowNum == 1)
    fig = get_figure(new_fig=True, no_axes=True)
    nt.ok_(type(fig) == plt.Figure)
    fig2, ax2 = get_figure(new_fig=True, subplot=[1,1,1])
    nt.ok_(ax2.colNum == 0)
    nt.ok_(ax2.rowNum == 0)
    plt.close('all')
    fig = plt.figure()
    ax  = fig.add_subplot(111)
    fig2, ax2 = get_figure(new_fig=False, new_axes=False)
    nt.ok_(fig2 == plt.gcf())
    nt.ok_(ax2 == plt.gca())
    plt.close('all')
Esempio n. 12
0
def test_get_figure():
    fig_old = plt.figure()
    fig, ax = get_figure(new_fig=False)
    nt.eq_(fig, fig_old)
    nt.eq_(ax.colNum, 0)
    nt.eq_(ax.rowNum, 0)

    fig1, ax1 = get_figure(new_fig=True, subplot=224)
    nt.ok_(fig1 != fig_old)
    nt.eq_(ax1.colNum, 1)
    nt.eq_(ax1.rowNum, 1)

    fig2, ax2 = get_figure(new_fig=True, subplot=[1, 1, 1])
    nt.eq_(ax2.colNum, 0)
    nt.eq_(ax2.rowNum, 0)
    plt.close('all')

    fig = plt.figure()
    ax = fig.add_subplot(111)
    fig2, ax2 = get_figure(new_fig=False)
    nt.eq_(fig2, plt.gcf())
    nt.eq_(ax2, plt.gca())
    plt.close('all')
Esempio n. 13
0
def test_get_figure():
    fig_old = plt.figure()
    fig, ax = get_figure(new_fig=False)
    nt.eq_(fig, fig_old)
    nt.eq_(ax.colNum, 0)
    nt.eq_(ax.rowNum, 0)

    fig1, ax1 = get_figure(new_fig=True, subplot=224)
    nt.ok_(fig1 != fig_old)
    nt.eq_(ax1.colNum, 1)
    nt.eq_(ax1.rowNum, 1)

    fig2, ax2 = get_figure(new_fig=True, subplot=[1, 1, 1])
    nt.eq_(ax2.colNum, 0)
    nt.eq_(ax2.rowNum, 0)
    plt.close('all')

    fig = plt.figure()
    ax = fig.add_subplot(111)
    fig2, ax2 = get_figure(new_fig=False)
    nt.eq_(fig2, plt.gcf())
    nt.eq_(ax2, plt.gca())
    plt.close('all')
Esempio n. 14
0
def test_get_figure():
    fig_old = plt.figure()
    fig, ax = get_figure(new_fig=False)
    assert fig == fig_old
    assert ax.get_subplotspec().colspan.start == 0
    assert ax.get_subplotspec().rowspan.start == 0

    fig1, ax1 = get_figure(new_fig=True, subplot=224)
    assert fig1 != fig_old
    assert ax1.get_subplotspec().colspan.start == 1
    assert ax1.get_subplotspec().rowspan.start == 1

    fig2, ax2 = get_figure(new_fig=True, subplot=[1, 1, 1])
    assert ax2.get_subplotspec().colspan.start == 0
    assert ax2.get_subplotspec().rowspan.start == 0
    plt.close('all')

    fig = plt.figure()
    ax = fig.add_subplot(111)
    fig2, ax2 = get_figure(new_fig=False)
    assert fig2 == plt.gcf()
    assert ax2 == plt.gca()
    plt.close('all')
Esempio n. 15
0
def test_get_figure():
    fig_old = plt.figure()
    fig, ax = get_figure(new_fig=False)
    nt.eq_(fig, fig_old)
    nt.eq_(ax.get_subplotspec().colspan.start, 0)
    nt.eq_(ax.get_subplotspec().rowspan.start, 0)

    fig1, ax1 = get_figure(new_fig=True, subplot=224)
    nt.ok_(fig1 != fig_old)
    nt.eq_(ax1.get_subplotspec().colspan.start, 1)
    nt.eq_(ax1.get_subplotspec().rowspan.start, 1)

    fig2, ax2 = get_figure(new_fig=True, subplot=[1, 1, 1])
    nt.eq_(ax2.get_subplotspec().colspan.start, 0)
    nt.eq_(ax2.get_subplotspec().rowspan.start, 0)
    plt.close('all')

    fig = plt.figure()
    ax = fig.add_subplot(111)
    fig2, ax2 = get_figure(new_fig=False)
    nt.eq_(fig2, plt.gcf())
    nt.eq_(ax2, plt.gca())
    plt.close('all')