def get_fig_3d(): fig = plt.figure() ax = fig.add_subplot((111), projection='3d') try: yield fig, ax finally: plt.close(fig)
def get_fig_2d(): fig = plt.figure() ax = fig.add_subplot(111) try: yield fig, ax finally: plt.close(fig)
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')
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')
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')
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')
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')
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')
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')
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')
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')
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') fig = plt.figure() ax = fig.add_subplot(111) ax.plot([0, 0], [1, 2], label='test') xlim = ax.get_xlim() ylim = ax.get_ylim() fig0 = plt.figure() ax0 = fig0.add_subplot((111), projection='3d') ax0.plot([0, 0], [1, 2], [2, 1]) xlim0 = ax0.get_xlim() ylim0 = ax0.get_ylim() zlim0 = ax0.get_zlim() def test_plot_title(): fig1, ax1 = plot_title(fig, ax)
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') fig = plt.figure() ax = fig.add_subplot(111) ax.plot([0,0], [1,2], label='test') xlim = ax.get_xlim() ylim = ax.get_ylim() fig0 = plt.figure() ax0 = fig0.add_subplot((111), projection='3d') ax0.plot([0,0], [1,2], [2,1]) xlim0 = ax0.get_xlim() ylim0 = ax0.get_ylim() zlim0 = ax0.get_zlim() def test_plot_title(): fig1, ax1 = plot_title(fig, ax) nt.ok_(ax1.get_title() == 'Figure')