def setup_plot(self, figure, name, xlabel, ylabel): plot = Subplot(figure, 111, axisbg='white', frameon='False') #plot.set_axis_bg_color('#000000') plot.set_title(name) plot.set_xlabel(xlabel) plot.set_ylabel(ylabel) return plot
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 words_in_topic(self, i_topic: int, axis: Subplot) -> AxesImage: """Plot the relative importance of words in a given topic. Parameters ---------- i_topic: int Index of the topic to plot. Numbering starts at 0. axis: Subplot The matplotlib axis to plot into. Returns ------- AxesImage The image with the produced word cloud. """ word_given_topic = dict(self.__word_given_topic[i_topic]) wordcloud = self.__wordcloud.generate_from_frequencies(word_given_topic) axis.set_title(f'Topic {i_topic}') axis.set_axis_off() return axis.imshow(wordcloud, interpolation='bilinear')
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)
win = gtk.Window() win.set_name("Embedding in GTK") win.connect("destroy", gtk.mainquit) win.set_border_width(5) vbox = gtk.VBox(spacing=3) win.add(vbox) vbox.show() fig = Figure(figsize=(5,4), dpi=100) ax = Subplot(fig, 111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) ax.plot(t,s) ax.set_title('click on line or text') fig.add_axis(ax) canvas = PickerCanvas(fig) canvas.show() vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, win) toolbar.show() vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE) win.show() gtk.mainloop()
win = gtk.Window() win.set_name("Embedding in GTK") win.connect("destroy", gtk.mainquit) win.set_border_width(5) vbox = gtk.VBox(spacing=3) win.add(vbox) vbox.show() fig = Figure(figsize=(5, 4), dpi=100) ax = Subplot(fig, 111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) ax.plot(t, s) ax.set_title("click on line or text") fig.add_axis(ax) canvas = PickerCanvas(fig) canvas.show() vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, win) toolbar.show() vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE) win.show() gtk.mainloop()
win = gtk.Window() win.set_name("Embedding in GTK") win.connect("destroy", gtk.mainquit) win.set_border_width(5) vbox = gtk.VBox(spacing=3) win.add(vbox) vbox.show() fig = Figure(figsize=(5, 4), dpi=100) ax = Subplot(fig, 111) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) ax.plot(t, s) ax.set_title('click on line or text') fig.add_axis(ax) canvas = PickerCanvas(fig) canvas.show() vbox.pack_start(canvas) toolbar = NavigationToolbar(canvas, win) toolbar.show() vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE) win.show() gtk.mainloop()