class WidgetsWrapper: def __init__(self): self.widgets = gtk.glade.XML('mpl_with_glade.glade') self.widgets.signal_autoconnect(GladeHandlers.__dict__) self.figure = Figure(figsize=(8, 6), dpi=72) self.axis = Subplot(self.figure, 111) self.figure.add_axis(self.axis) t = arange(0.0, 3.0, 0.01) s = sin(2 * pi * t) self.axis.plot(t, s) self.axis.set_xlabel('time (s)') self.axis.set_ylabel('voltage') self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea self.canvas.show() self['vboxMain'].pack_start(self.canvas, gtk.TRUE, gtk.TRUE) self['vboxMain'].show() # below is optional if you want the navigation toolbar self.navToolbar = NavigationToolbar(self.canvas, self['windowMain']) self.navToolbar.lastDir = '/var/tmp/' self['vboxMain'].pack_start(self.navToolbar) self.navToolbar.show() sep = gtk.HSeparator() sep.show() self['vboxMain'].pack_start(sep, gtk.TRUE, gtk.TRUE) self['vboxMain'].reorder_child(self['buttonClickMe'], -1) def __getitem__(self, key): return self.widgets.get_widget(key)
class WidgetsWrapper: def __init__(self): self.widgets = gtk.glade.XML('mpl_with_glade.glade') self.widgets.signal_autoconnect(GladeHandlers.__dict__) self.figure = Figure(figsize=(8,6), dpi=72) self.axis = Subplot(self.figure, 111) self.figure.add_axis(self.axis) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) self.axis.plot(t,s) self.axis.set_xlabel('time (s)') self.axis.set_ylabel('voltage') self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea self.canvas.show() self['vboxMain'].pack_start(self.canvas, gtk.TRUE, gtk.TRUE) self['vboxMain'].show() # below is optional if you want the navigation toolbar self.navToolbar = NavigationToolbar(self.canvas, self['windowMain']) self.navToolbar.lastDir = '/var/tmp/' self['vboxMain'].pack_start(self.navToolbar) self.navToolbar.show() sep = gtk.HSeparator() sep.show() self['vboxMain'].pack_start(sep, gtk.TRUE, gtk.TRUE) self['vboxMain'].reorder_child(self['buttonClickMe'],-1) def __getitem__(self, key): return self.widgets.get_widget(key)
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 _modify_axis( ax: Subplot, time: list, data: list, *, color: str, label: str, ): ax.set_ylabel(label, color=color) if isinstance(time[0], list): for plot in zip(time, data): ax.plot(*plot) else: ax.plot(time, data, color=color) ax.tick_params(axis='y', labelcolor=color) ax.xaxis.set_major_locator(mdates.MinuteLocator(interval=5)) ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M"))
import matplotlib matplotlib.use('GD') from matplotlib.backends.backend_gd import Figure, show from matplotlib.axes import Subplot dpi = 100 figsize = (5, 5) f = Figure(figsize, dpi) a = Subplot(f, 111) f.add_axis(a) l = a.plot([1,2,3], [4,5,6]) a.set_xlabel('time (s)') a.set_ylabel('Signal 2') f.print_figure('gdtest', dpi) show()
import matplotlib matplotlib.use('GD') from matplotlib.backends.backend_gd import Figure, show from matplotlib.axes import Subplot dpi = 100 figsize = (5, 5) f = Figure(figsize, dpi) a = Subplot(f, 111) f.add_axis(a) l = a.plot([1, 2, 3], [4, 5, 6]) a.set_xlabel('time (s)') a.set_ylabel('Signal 2') f.print_figure('gdtest', dpi) show()