def test_saving_plot(self):
     this_filename = os.path.join(
         dcs.get_tests_dir(), self.opts.case_name + ' - Figure Title.png')
     self.opts.save_plot = True
     dcs.setup_plots(self.fig, self.opts)
     # remove file
     os.remove(this_filename)
 def test_multiple_figs(self):
     fig_list = [self.fig]
     (new_fig, ax) = plt.subplots()
     ax.plot(0, 0)
     fig_list.append(new_fig)
     dcs.setup_plots(fig_list, self.opts)
     plt.close(new_fig)
 def test_multiple_figs(self):
     fig_list = [self.fig]
     (new_fig, ax) = plt.subplots()
     ax.plot(0, 0)
     fig_list.append(new_fig)
     dcs.setup_plots(fig_list, self.opts)
     plt.close(new_fig)
 def test_show_link(self):
     this_filename = os.path.join(dcs.get_tests_dir(), self.opts.case_name + ' - Figure Title.png')
     self.opts.save_plot = True
     self.opts.show_link = True
     with dcs.capture_output() as out:
         dcs.setup_plots(self.fig, self.opts)
     output = out.getvalue().strip()
     out.close()
     # remove file
     os.remove(this_filename)
     self.assertTrue(output.startswith('Plots saved to <a href="'))
 def test_show_link(self):
     this_filename = os.path.join(
         dcs.get_tests_dir(), self.opts.case_name + ' - Figure Title.png')
     self.opts.save_plot = True
     self.opts.show_link = True
     with dcs.capture_output() as out:
         dcs.setup_plots(self.fig, self.opts)
     output = out.getvalue().strip()
     out.close()
     # remove file
     os.remove(this_filename)
     self.assertTrue(output.startswith('Plots saved to <a href="'))
 def test_not_showing_plot(self):
     self.opts.show_plot = False
     dcs.setup_plots(self.fig, self.opts)
 def test_no_title(self):
     self.opts.case_name = ''
     dcs.setup_plots(self.fig, self.opts)
 def test_title(self):
     dcs.setup_plots(self.fig, self.opts)
Beispiel #9
0
def plot_cube(piece, title=None, opts=None):
    r"""
    Plots the given cube as a 3D plot.

    Parameters
    ----------
    cube : (3,3,3) ndarray of int
        Piece layout
    title : str, optional
        Title to put on the plot and use to save to disk
    opts : class dstauffman.Opts, optional
        Plotting options

    Returns
    -------
    fig : class matplotlib.pyplot.figure
        Figure handle

    Notes
    -----
    #.  Written by David C. Stauffer in June 2015.

    Examples
    --------
    >>> from dstauffman2.games.brick import plot_cube, R, N
    >>> import numpy as np
    >>> piece = np.array([\
    ...    [[R, N, N],[N, N, N],[N, N, N]], \
    ...    [[R, N, N],[N, N, N],[N, N, N]], \
    ...    [[R, N, N],[N, N, N],[N, N, N]]])
    >>> fig = plot_cube(piece, title='Test Plot')

    Close plot
    >>> import matplotlib.pyplot as plt
    >>> plt.close(fig)

    """
    # check for opts
    if opts is None:
        opts = Opts()
    # turn interactive plotting off
    plt.ioff()
    # create the figure
    fig = plt.figure()
    # create the axis
    ax = fig.add_subplot(111, projection='3d')
    # TODO: put back once MPL is fixed: ax.set_aspect('equal')
    # set the title
    if title is not None:
        fig.canvas.manager.set_window_title(title)
        ax.set_title(title)
    # draw each of the 27 cubes
    for i in range(3):
        for j in range(3):
            for k in range(3):
                _draw_cube(ax,
                           xs=i,
                           ys=j,
                           zs=k,
                           color=_get_color(piece[i, j, k]))

    # set the limits
    ax.set_xlim3d(-1, 4)
    ax.set_ylim3d(-1, 4)
    ax.set_zlim3d(-1, 4)

    # Turn the tick labels off
    ax.set_xticklabels([])
    ax.set_yticklabels([])
    ax.set_zticklabels([])

    # configure the plot
    setup_plots(fig, opts)

    # return the resulting figure handle
    return fig
 def test_not_showing_plot(self):
     self.opts.show_plot = False
     dcs.setup_plots(self.fig, self.opts)
 def test_no_title(self):
     self.opts.case_name = ''
     dcs.setup_plots(self.fig, self.opts)
 def test_title(self):
     dcs.setup_plots(self.fig, self.opts)
 def test_saving_plot(self):
     this_filename = os.path.join(dcs.get_tests_dir(), self.opts.case_name + ' - Figure Title.png')
     self.opts.save_plot = True
     dcs.setup_plots(self.fig, self.opts)
     # remove file
     os.remove(this_filename)