Example #1
0
    def _plot_digit(self, digit: numpy.ndarray, suptitle: str, title: str,
                    subfolder: str, filename: str, extension: str) -> None:
        """
        Plots and saves an image of a digit.

        :param digit: the digit to be plotted.
        :param suptitle: the super title of the figure.
        :param title: the title of the figure.
        :param subfolder: the subfolder for the image to be saved.
        :param filename: the image's filename.
        :param extension: the extension of the file to be saved.
            Acceptable values: 'png', 'jpg', 'jpeg'.
        """
        # Create a subfolder for the image.
        create_folder(self._folder + '/' + subfolder)

        # Change the shape of the image to 2D.
        digit.shape = (28, 28)

        # Create a subplot.
        fig, ax = pyplot.subplots(figsize=(3, 3.5))
        # Create a super title.
        fig.suptitle(suptitle + '\n' + title, fontsize='large')
        # Create an image from the digit's pixels. The pixels are not rgb so cmap should be gray.
        ax.imshow(digit, cmap='gray')
        # Remove ticks
        ax.set_xticks([])
        ax.set_yticks([])

        # Save and plot the image.
        fig.savefig(self._folder + '/' + subfolder + '/' + filename + '.' +
                    extension)
        pyplot.show()
Example #2
0
    def heatmap_correlation(self,
                            data: numpy.ndarray,
                            xlabel: str,
                            ylabel: str,
                            subfolder: str = 'heatmaps',
                            filename: str = 'heatmap_correlation',
                            extension: str = 'png') -> None:
        """
        Create and save a heatmap, representing correlation.

        :param data: the correlated data to be plotted.
        :param xlabel: the x ax's label.
        :param ylabel: the y ax's label.
        :param subfolder: the subfolder for the heatmap to be saved.
        :param filename: the heatmap's filename.
        :param extension: the extension of the file to be saved.
            Acceptable values: 'png', 'jpg', 'jpeg'.
        """
        # Create a subfolder for the heatmap.
        create_folder(self._folder + '/' + subfolder)

        # Create a subplot.
        fig, ax = pyplot.subplots()

        # Create the heatmap.
        img = ax.matshow(data, aspect='auto')
        # Add a colorbar, showing the percentage of the correlation.
        pyplot.colorbar(img)
        pyplot.xlabel(xlabel)
        pyplot.ylabel(ylabel)

        # Save and plot the heatmap.
        pyplot.savefig(self._folder + '/' + subfolder + '/' + filename + '.' +
                       extension)
        pyplot.show()
Example #3
0
    def _plot_email(self, email: numpy.ndarray, suptitle: str, title: str,
                    subfolder: str, filename: str, extension: str) -> None:
        """
        Plots and saves an email's figure with two bar diagrams.

        One for the frequency of the words and the characters of the email.

        One for the capital letters information of the email.

        :param email: the email to be plotted.
        :param suptitle: the super title of the figure.
        :param title: the title of the figure.
        :param subfolder: the subfolder for the diagram to be saved.
        :param filename: the diagram's filename.
        :param extension: the extension of the file to be saved.
            Acceptable values: 'png', 'jpg', 'jpeg'.
        """
        # Create a subfolder for the plot.
        create_folder(self._folder + '/' + subfolder)

        # Create two subplots.
        fig, (ax1, ax2) = pyplot.subplots(1, 2, figsize=(7, 9))
        # Create a super title.
        fig.suptitle(suptitle + '\n' + title, fontsize='large')

        # Create y ax values for the the words frequencies.
        indexes = numpy.arange(len(email[:-3]))
        # Create a bar diagram for the words frequencies.
        ax1.bar(indexes, email[:-3], align='center')
        ax1.set_xlabel("Words", fontsize='large')
        ax1.set_ylabel("Frequency", fontsize='large')

        # Create y ax values for the the capital letters information.
        indexes = numpy.arange(len(email[-3:]))
        # Create a bar diagram for the capital letters information.
        ax2.bar(indexes, email[-3:], align='center')
        ax2.set_xticklabels(label
                            for label in ['', 'average', 'longest', 'total'])
        ax2.set_xlabel("Capitals", fontsize='large')

        # Save and plot the figure.
        fig.savefig(self._folder + '/' + subfolder + '/' + filename + '.' +
                    extension)
        pyplot.show()
Example #4
0
    def __init__(self, folder: str = 'plots', mode: str = 'show'):
        # Get plotter's mode and check it's value.
        self.mode = mode
        if self.mode != 'show' and self.mode != 'save' and self.mode != 'both':
            raise ValueError(
                'Plotter\'s mode can be \'save\', \'show\' or \'both\'.\nGot {} instead.'
                .format(self.mode))

        # Create a folder for the plots, if needed.
        if self.mode == 'save' or self.mode == 'both':
            self._folder = create_folder(folder)

        self.subfolder: str = ''
        self.suptitle: str = ''
        self.title: str = ''
        self.filename: str = 'plot'
        self.extension: str = 'png'
        self.xlabel: str = ''
        self.ylabel: str = ''
Example #5
0
 def _create_plot_folder(self) -> None:
     """" Create a plot's subfolder. """
     if self.mode == 'save' or self.mode == 'both':
         create_folder(self._folder + '/' + self.subfolder)
 def _create_language_assets(self, path):
     create_folder(path)
     create_file(f"{path}dictionary.json", '{}')
     create_file(f"{path}words_list")
Example #7
0
 def __init__(self, folder='plots'):
     self._folder = folder
     # Create a folder for the plots.
     create_folder(folder)