Exemplo n.º 1
0
def test_base64():
    import matplotlib
    matplotlib.use('Agg')

    import matplotlib.pyplot as plt
    fig = plt.figure()
    plt.plot(range(10))
    res = jutil.fig2base64(fig, 'png')
    res = jutil.fig2base64(fig, 'pdf')
Exemplo n.º 2
0
    def show_fig(self, fig, file_name):
        """
        Save fig object to self.output_folder/filename.
        
        Parameters
        ----------
        fig : matplotlib.figure.Figure
        file_name : str

        """

        self.fig_objs[file_name] = fig

        if self.output_format in ['pdf', 'png', 'jpg']:
            fp = os.path.join(self.output_folder,
                              '.'.join([file_name, self.output_format]))
            jutil.create_dir(fp)
            fig.savefig(fp)
            print("Figure saved: {}".format(fp))
        elif self.output_format == 'base64':
            fig_b64 = jutil.fig2base64(fig, 'png')
            self.fig_data[file_name] = fig_b64
            print("Base64 data of figure {} will be stored in dictionary.".
                  format(file_name))
        elif self.output_format == 'plot':
            fig.show()
        else:
            raise NotImplementedError("output_format = {}".format(
                self.output_format))
Exemplo n.º 3
0
    def show_fig(self, fig, file_name):
        """
        Save fig object to self.output_folder/filename.
        
        Parameters
        ----------
        fig : matplotlib.figure.Figure
        file_name : str

        """
        
        self.fig_objs[file_name] = fig
        
        if self.output_format in ['pdf', 'png', 'jpg']:
            fp = os.path.join(self.output_folder, '.'.join([file_name, self.output_format]))
            jutil.create_dir(fp)
            fig.savefig(fp)
            print("Figure saved: {}".format(fp))
        elif self.output_format == 'base64':
            fig_b64 = jutil.fig2base64(fig, 'png')
            self.fig_data[file_name] = fig_b64
            print("Base64 data of figure {} will be stored in dictionary.".format(file_name))
        elif self.output_format == 'plot':
            fig.show()
        else:
            raise NotImplementedError("output_format = {}".format(self.output_format))