def topics(self, axis: Subplot) -> BarContainer: """Plot the relative importance of the individual topics. Parameters ---------- axis: Subplot The matplotlib axis to plot into. Returns ------- BarContainer The container for the bars plotted into the given axis. """ colors = [f'C{color}' for color in self.__topic_range] axis.set(xlabel='Topic', ylabel='Importance') axis.set_title('Topic distribution') return axis.bar(self.__topic_range, self.__topics, color=colors, tick_label=self.__topic_range)
def topics_in_doc(self, i_doc: int, axis: Subplot) -> BarContainer: """Plot the relative weights of topics in a given document. Parameters ---------- i_doc: int Index of the document to plot. Numbering starts at 0. axis: Subplot The matplotlib axis to plot into. Returns ------- BarContainer The container for the bars plotted into the given axis. """ colors = [f'C{color}' for color in self.__topic_range] axis.set(xlabel='Topic', ylabel='Importance', title=f'Document {i_doc}') return axis.bar(self.__topic_range, self.__topic_given_doc[i_doc], color=colors, tick_label=self.__topic_range)
def prediction(self, doc: str, axis: Subplot) -> BarContainer: """Plot the predicted relative weights of topics in a new document. Parameters ---------- doc: str A new document given as a single string. axis: Subplot The matplotlib axis to plot into. Returns ------- BarContainer The container for the bars plotted into the given axis. """ colors = [f'C{color}' for color in self.__topic_range] prediction, n_unknown_words, _ = self.__predict(doc) axis.set(xlabel='Topic', ylabel='Importance') axis.set_title(f'Number of unknown words: {n_unknown_words}') return axis.bar(self.__topic_range, prediction, color=colors, tick_label=self.__topic_range)