コード例 #1
0
ファイル: pygobj_plots.py プロジェクト: wisecg/datacage
    def __init__(self):
        Gtk.Window.__init__(self, title="GtkListStore demo")
        self.connect("delete-event", Gtk.main_quit)
        # self.connect("destroy", Gtk.main_quit) # no difference?

        xpix, ypix, dpi = 600, 600, 100
        self.set_default_size(xpix, ypix)
        self.set_border_width(8)

        # -- overall window box
        # docs recommend we switch this Gtk.Box to a Gtk.Grid
        # https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/VBox.html#Gtk.VBox
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(vbox)
        label = Gtk.Label(label='Double click a row to plot the data')
        vbox.pack_start(label, False, False, 0)

        # -- ScrolledWindow to hold our data table
        self.sw = Gtk.ScrolledWindow()
        self.sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        self.sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        vbox.pack_start(self.sw, True, True, 0)

        # set data
        self.nrows, self.ncols = 20, 10
        self.data = np.random.random((self.nrows, self.ncols))

        # declare the model (a Gtk.ListStore) and TreeView for our data table
        model = self.create_table()
        self.treeview = Gtk.TreeView(model=model)

        # -- Figure for the plot of each row
        fig = Figure(figsize=(xpix / dpi, ypix / dpi), dpi=dpi)
        self.set_default_size(xpix, ypix)
        self.canvas = FigureCanvas(fig)
        vbox.pack_start(self.canvas, True, True, 0)

        ax = fig.add_subplot(111)
        self.line, = ax.plot(self.data[0, :], 'go')  # plot first row

        # -- set an action: update plot when you dblclick a row
        self.treeview.connect('row-activated', self.plot_row)
        self.sw.add(self.treeview)

        self.add_columns()  # load our data

        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK
                        | Gdk.EventMask.KEY_PRESS_MASK
                        | Gdk.EventMask.KEY_RELEASE_MASK)
コード例 #2
0
ファイル: dsppac_main.py プロジェクト: F1sher/dsppac
    def attach_Figs(self, grid):
        for i in range(4):
            en_d_vbox_name = "en_d{:d}_vbox".format(i)
            en_d_vbox = self.builder.get_object(en_d_vbox_name)
            en_d_vbox.pack_start(FigureCanvas(self.en_fig[i]), True, True, 0)

        col, row = 0, 1
        for i in range(6):
            grid.attach(FigureCanvas(self.t_fig[2 * i]), col, row, 1, 1)
            col += 1

        col, row = 0, 2
        for i in range(6):
            grid.attach(FigureCanvas(self.t_fig[2 * i + 1]), col, row, 1, 1)
            col += 1
コード例 #3
0
def main():
    window = gtk.Window()
    window.set_default_size(800, 600)

    # matplotlib
    x_vec = np.arange(-10, 10, 0.01)
    y_vec = np.sin(2 * 2 * np.pi * x_vec) * 1 / np.sqrt(2 * np.pi) * np.exp(
        -(x_vec**2) / 2)

    #fig = plt.figure(figsize=(8.0, 6.0), dpi=100)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x_vec, y_vec)

    # add the image to the window
    scrolled_window = gtk.ScrolledWindow()
    window.add(scrolled_window)

    canvas = FigureCanvas(fig)
    canvas.set_size_request(800, 600)  # optional...
    scrolled_window.add_with_viewport(canvas)

    # main
    window.connect(
        "delete-event", gtk.main_quit
    )  # ask to quit the application when the close button is clicked
    window.show_all()  # display the window
    gtk.main()  # GTK+ main loop
コード例 #4
0
    def __init__(self, data_source):
        years = mdates.YearLocator(2)  # every year
        months = mdates.MonthLocator()  # every month
        yearsFmt = mdates.DateFormatter('%y')

        dt_list, ssn_list = data_source.get_plotting_data()

        self.figure = Figure(figsize=(12, 8), dpi=72)
        self.figure.patch.set_facecolor('white')
        self.figure.subplots_adjust(bottom=0.2)
        self.axis = self.figure.add_subplot(111)
        self.axis.plot_date(dt_list, ssn_list, '-', lw=2)
        self.axis.axvline(date.today(), color='r')

        # format the ticks
        self.axis.xaxis.set_major_locator(years)
        self.axis.xaxis.set_major_formatter(yearsFmt)

        self.axis.grid(True)

        # rotates and right aligns the x labels, and moves the bottom of the
        # axes up to make room for them
        # The following line currently breaks voacapgui if the thumbnail is
        # inserted into a panel
        # self.figure.autofmt_xdate(rotation=90)

        self.canvas = FigureCanvas(self.figure)  # a Gtk.DrawingArea
コード例 #5
0
def graph_c(funcion, initial_value, last_value):
    function = Fun(funcion)

    win = Gtk.Window()
    win.connect("destroy", lambda x: Gtk.main_quit())
    win.set_default_size(640, 480)
    win.set_title("Embedding in GTK")

    vbox = Gtk.VBox()
    win.add(vbox)

    fig = Figure(figsize=(5, 4), dpi=100)
    ax = fig.add_subplot(111)
    x = np.arange(initial_value, last_value)
    y = [function.evaluate2(i) for i in x]
    ax.plot(x, y)
    dev = Fun(derivate_function(funcion))
    derivada = [dev.evaluate2(i) for i in x]
    ax.plot(x, derivada)

    canvas = FigureCanvas(fig)  # a Gtk.DrawingArea
    vbox.pack_start(canvas, True, True, 0)
    toolbar = NavigationToolbar(canvas, win)
    vbox.pack_start(toolbar, False, False, 0)

    win.show_all()
    Gtk.main()
コード例 #6
0
ファイル: img.py プロジェクト: ke8ctn/gtknodes
    def __init__(self, *args, **kwds):
        super().__init__(*args, **kwds)

        self.set_label("Image Plot")
        self.connect("node_func_clicked", self.remove)

        # create input socket
        lbl = Gtk.Label.new("Input")
        lbl.set_xalign(0.0)
        node_socket_input = self.item_add(lbl, GtkNodes.NodeSocketIO.SINK)
        node_socket_input.connect("socket_incoming", self.node_socket_incoming)

        # the compatibility key
        node_socket_input.set_key(1234)
        node_socket_input.set_rgba(get_rgba('darkturquoise'))

        f = Figure(figsize=(5, 4), dpi=100)
        self.a = f.add_subplot(111)

        sw = Gtk.ScrolledWindow()
        sw.set_border_width(10)

        self.canvas = FigureCanvas(f)
        sw.add(self.canvas)
        sw.set_size_request(200, 200)

        self.item_add(sw, GtkNodes.NodeSocketIO.DISABLE)
        self.set_child_packing(sw, True, True, 0, Gtk.PackType.END)
コード例 #7
0
    def final_clicked(self, widget):

        self.grid.remove(self.label7)
        self.grid.remove(self.label8)
        self.grid.remove(self.canvas)
        f = Figure()
        ax = f.add_subplot(111)

        ax.scatter(np.arange(1,
                             len(self.gensel.scores_best) + 1, 1),
                   self.gensel.scores_best,
                   label='Best')
        ax.plot(np.arange(1,
                          len(self.gensel.scores_best) + 1, 1),
                self.gensel.scores_avg,
                label='Average')

        self.canvas = FigureCanvas(f)  # a Gtk.DrawingArea
        self.canvas.set_size_request(800, 600)
        self.grid.attach(self.canvas, 4, 0, 4, 4)

        self.gensel.scores_best.sort(reverse=True)

        self.label7 = Gtk.Label()
        self.label7.set_text("Accuracy after feature selection: {0}".format(
            self.gensel.scores_best[0]))
        self.grid.attach(self.label7, 4, 4, 4, 1)

        self.label8 = Gtk.Label()
        self.label8.set_text("Feature Subset selected: {0}".format(
            self.gensel.chromosomes_best[0]))
        self.grid.attach(self.label8, 4, 5, 4, 1)

        self.show_all()
コード例 #8
0
    def __init__(self, yrange=(0, 1), xrange=10, update_interval=50):
        super(Graph, self).__init__(hexpand=True, vexpand=True)

        self.range = xrange
        self.interval = update_interval
        self.last_velocidad = 0
        self.last_torque = 0
        self.last_vel_deseada = 0
        self.last_time = 0

        self.fig = plt.figure()
        self.ax = self.fig.subplots()

        self.xdata, self.ydata_velocidad = [], []
        self.ydata_torque = []
        self.ydata_vel_deseada = []

        self.ln_velocidad, = self.ax.plot([], [], label='Velocidad')
        self.ln_torque, = self.ax.plot([], [], label='Torque')
        self.ln_vel_deseada, = self.ax.plot([], [],
                                            'r',
                                            label='Velocidad deseada')
        self.ax.legend()
        self.ax.grid(True)

        self.on_frame_callback = []

        self.ax.set_xlim(-self.range, 0)
        self.ax.set_ylabel('Velocidad / Torque')
        self.ax.set_ylim(yrange[0], yrange[1])

        self.ax.set_xlabel('Segundos')

        self.canvas = FigureCanvas(self.fig)
        self.add(self.canvas)
コード例 #9
0
    def __init__(self, **kw):
        super(PlotterWindow, self).__init__(**kw)
        self.set_title("Real-time plotting")
        self.set_default_size(600, 400)
        # self.grid = Gtk.Grid()
        # self.add(self.grid)

        self.i = 0
        self.before = self.prepare_cpu_usage()

        self.fig = Figure()
        ax = self.fig.add_subplot(111)

        ax.set_xlim(0, 30)
        ax.set_ylim([0, 100])

        ax.set_autoscale_on(False)

        self.user, self.nice, self.sys, self.idle = [], [], [], []
        self.l_user, = ax.plot([], self.user, label='User %')
        self.l_nice, = ax.plot([], self.nice, label='Nice %')
        self.l_sys, = ax.plot([], self.sys, label='Sys %')
        self.l_idle, = ax.plot([], self.idle, label='Idle %')

        ax.legend()
        self.canvas = FigureCanvas(self.fig)
        self.add(self.canvas)

        self.update_draw()

        GLib.idle_add(self.update_draw)
コード例 #10
0
ファイル: charts.py プロジェクト: benreu/PyGtk-Posting
 def create_window_using_tuple(self, tupl, title):
     window = Gtk.Window()
     box = Gtk.VBox()
     window.add(box)
     figure = Figure(figsize=(4, 4), dpi=100)
     canvas = FigureCanvas(figure)
     box.pack_start(canvas, True, True, 0)
     toolbar = NavigationToolbar(canvas, window)
     box.pack_start(toolbar, False, False, 0)
     subplot = figure.add_subplot(111)
     amounts = list()
     dates = list()
     for row in tupl:
         amounts.append(row[0])
         dates.append(row[1])
     subplot.bar(dates, amounts, width=10)
     subplot.set_xticks(dates)
     subplot.set_xticklabels(dates)
     for index, data in enumerate(amounts):
         subplot.text(x=dates[index], y=data, s=f"{data}", ha='center')
     figure.autofmt_xdate()
     subplot.set_title(title)
     window.set_size_request(400, 300)
     window.set_title(title)
     window.set_icon_name('pygtk-posting')
     window.show_all()
コード例 #11
0
    def draw_piechart(self):

        labels = []
        sizes = []
        colors = [
            '#ffffff', '#eeeeee', '#dddddd', '#cccccc', '#bbbbbb', '#aaaaaa',
            '#999999', '#888888'
        ]

        i = 0
        other_percent = 0
        for item in self.portfolio["items"]:
            if i < 7:
                labels.append(" " + item['ticker'] + " ")
                sizes.append(item['percent'])
            else:
                other_percent += item['percent']
            i += 1

        if other_percent > 0:
            labels.append(" другие ")
            sizes.append(other_percent)

        fig, ax = plt.subplots()

        fig.patch.set_facecolor('white')
        fig.patch.set_alpha(0)

        wedges, text, autotext = ax.pie(sizes,
                                        colors=colors,
                                        labels=labels,
                                        autopct='%1.1f%%',
                                        startangle=0)
        plt.setp(wedges, width=0.25)
        #plt.setp( wedges, )

        for w in wedges:
            w.set_linewidth(1)
            w.set_linestyle('-')
            w.set_edgecolor('#555555')
            w.set_capstyle('projecting')

        fig = plt.gcf()
        ax.axis('equal')

        for t in text:
            t.set_color("#999999")
            #t.set_backgroundcolor("white")
            t.set_fontname("Play")
            t.set_fontsize(8)

        for t in autotext:
            t.set_color("#888888")
            t.set_fontname("Play")
            t.set_fontsize(7)

        canvas = FigureCanvas(fig)
        canvas.set_size_request(300, 300)

        self.box.pack_start(canvas, expand=False, fill=True, padding=0)
コード例 #12
0
ファイル: PlotWindow.py プロジェクト: pcm-ca/MFV
    def __init__(self, parent, simulation, colormap, statBar, z_lims=None, y_lims=None, binary_colors=False):
        self.parent = parent
        self.simulation = simulation
        self.colormap = colormap
        self.format = '%.2E'
        self.statBar = statBar

        self.builder = Gtk.Builder()
        
        self.builder.add_from_file(resource_dir + "/toolbar.glade")
        wnd = self.builder.get_object("wndToolBar")
        self.toolbar = self.builder.get_object("boxToolBar")
        self.boxLimits = self.builder.get_object("boxLimits")
        wnd.remove(self.toolbar)
        self.btnApplyLimits = self.builder.get_object("btnApplyLimits")
        self.txtMinLimit = self.builder.get_object("txtMinLimit")
        self.txtMaxLimit = self.builder.get_object("txtMaxLimit")
        self.lblBmin = self.builder.get_object("lblBmin")
        self.lblBmax = self.builder.get_object("lblBmax")
        self.btnRestore = self.builder.get_object("btnRestore")
        self.btnSave = self.builder.get_object("btnSave")
        self.btnHideShowCoils = self.builder.get_object("btnHideShowCoils")
        self.lblHideShowCoils = self.builder.get_object("lblHideShowCoils")

        self.txtMaxLimit.connect("key-press-event", self.on_key_press_event)
        self.txtMinLimit.connect("key-press-event", self.on_key_press_event)


        self.boxPlot = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL)

        self.fig = Figure(figsize=(10, 10), dpi=80)
        self.fig.patch.set_facecolor((242 / 255, 241 / 255, 240 / 255))
        self.canvas = FigureCanvas(self.fig)
        self.fig.canvas.mpl_connect("button_press_event", self.on_click)
        
        self.boxPlot.pack_start(self.canvas, True, True, 0)
        self.boxPlot.pack_start(self.toolbar, False, True, 0)

        self.btnRestore.connect("clicked", self.on_initial_plot)
        self.btnApplyLimits.connect("clicked", self.on_apply_limits)
        self.btnSave.connect("clicked", self.on_save)
        self.btnHideShowCoils.connect("clicked", self.on_hide_show_coils)

        self.z_lims = (self.simulation.z_min, self.simulation.z_max)
        self.y_lims = (self.simulation.y_min, self.simulation.y_max)
        
        if z_lims:
            self.z_lims = z_lims
        if y_lims:
            self.y_lims = y_lims

        self.initial_norm = self.simulation.norm.copy()

        self.binary_colors = binary_colors
        self.selected_point = [[], []]
        self.rect = None
        
        self.plot_coils = False

        self.on_initial_plot(None)
コード例 #13
0
    def __init__(self, app):

        Gtk.Window.__init__(self, application=app)
        self.set_default_size(800, 600)

        # ------------------------------------------------------------------

        # Functions to plot
        x = np.linspace(0, 5, 11)
        y = x**2

        # Figure as wrapper for plots
        fig = plt.figure()
        axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])

        # add description of axes
        axes.set_xlabel("X")
        axes.set_ylabel("Y")

        # add title of plot
        axes.set_title("Title")

        # Plot1
        axes.plot(x, y)

        # ------------------------------------------------------------------

        canvas = FigureCanvas(fig)
        canvas.set_size_request(400, 300)

        self.add(canvas)
コード例 #14
0
    def best_fit(self, temp_data, dimension):

        f = Figure(figsize=(5, 4), dpi=100)
        a = f.add_subplot(111)
        s = temp_data
        t = range(1, len(temp_data) + 1)
        fit = np.poly1d(np.polyfit(t, s, dimension))
        format_fit = str(fit).replace('\n', '')
        win = Gtk.Window()
        win.set_default_size(1000, 1000)
        title = self.questions[
            self.active_question].get_question() + "(y = %s)" % format_fit
        win.set_title(title)

        a.plot(s)
        a.plot(fit(t))
        a.set_xlabel("Time(x)")
        a.set_ylabel("Input(y)")
        sw = Gtk.ScrolledWindow()
        win.add(sw)
        # A scrolled window border goes outside the scrollbars and viewport
        sw.set_border_width(10)
        canvas = FigureCanvas(f)  # a Gtk.DrawingArea
        canvas.set_size_request(800, 600)
        sw.add_with_viewport(canvas)

        win.show_all()
コード例 #15
0
def show_fourier(fr, armonicas, xl, xu):

    #cantidad de armonicas al numero de armonica a calcular
    cant_armo = armonicas + (armonicas - 1)

    #preparar ventana para mostrar resultado
    win = Gtk.Window()
    win.connect("delete-event", Gtk.main_quit)
    win.set_default_size(800, 600)
    win.set_title("Embedding in GTK")
    f = Figure(figsize=(800 / 96, 800 / 96), dpi=96)
    a = f.add_subplot(111)

    #algoritmo para generar series de fourier
    xs = np.arange(xl, xu, 0.001)
    generar = generador_armonicas(fr)
    ys = [generar(cant_armo, x) for x in xs]
    a.plot(xs, ys)

    #mostrar resultados
    sw = Gtk.ScrolledWindow()
    win.add(sw)
    sw.set_border_width(10)
    canvas = FigureCanvas(f)  # a Gtk.DrawingArea
    canvas.set_size_request(800, 600)
    sw.add_with_viewport(canvas)
    win.show_all()
    Gtk.main()
コード例 #16
0
    def _createPlot(self):
        self.fig = plt.Figure(figsize=(5, 4), dpi=100)
        self.ax = self.fig.add_subplot()

        self.canvas = FigureCanvas(self.fig)  # a Gtk.DrawingArea
        self.canvas.set_size_request(800, 600)
        self.left.add(self.canvas)
コード例 #17
0
def graphic(funcion, initial_value, iterations):
    function = Function(funcion)

    win = Gtk.Window()
    win.connect("destroy", lambda x: Gtk.main_quit())
    win.set_default_size(640, 480)
    win.set_title("Embedding in GTK")

    vbox = Gtk.VBox()
    win.add(vbox)

    increment = 0.01
    final_value = math.fabs(initial_value+math.fabs(increment*100))

    fig = Figure(figsize=(5, 4), dpi=100)
    ax = fig.add_subplot(111)
    x = np.arange(-50, 3, 0.01)
    y = [function.evaluate2(i) for i in x]
    ax.plot(x, y)

    canvas = FigureCanvas(fig)  # a Gtk.DrawingArea
    vbox.pack_start(canvas, True, True, 0)
    toolbar = NavigationToolbar(canvas, win)
    vbox.pack_start(toolbar, False, False, 0)

    win.show_all()
    Gtk.main()
コード例 #18
0
    def __init__(self, app):

        Gtk.Window.__init__(self, application=app)
        self.set_default_size(800, 600)

        # ------------------------------------------------------------------

        # Functions to plot
        x = np.linspace(0, 5, 11)
        y = x**2

        # Figure and axes
        fig, axes = plt.subplots(nrows=1, ncols=2)

        # Plot1
        axes[0].plot(x, y)

        # Plot2
        axes[1].plot(y, x)

        # ------------------------------------------------------------------
        canvas = FigureCanvas(fig)
        canvas.set_size_request(400, 300)

        self.add(canvas)
コード例 #19
0
def drawPlot(filename=""):
    if sw.get_child() != None:
        sw.remove(sw.get_child())

    figure = Figure(figsize=(8, 8), dpi=80)
    axis = figure.add_subplot(111)
    x, y = calculateValues()
    axis.plot(x, y)
    if plot["zoom"]:
        last = y[0]
        for i in range(len(y)):
            if y[i] > last:
                break
            last = y[i]
        axis.set_ylim(top=y[i:].max() + abs(y[i:].max() * 0.075),
                      bottom=y[i:].min() - abs(y[i:].min() * 0.075))
    else:
        axis.set_ylim(top=y.max() + abs(y.max() * 0.075),
                      bottom=y.min() - abs(y.min() * 0.075))
    if plot["lambda"]:
        axis.set_xlabel("Wellenlänge in m")
    else:
        axis.set_xlabel("Glanzinkel in °")
    if plot["persecond"]:
        axis.set_ylabel("Zählrahte in 1/s")
    else:
        axis.set_ylabel("Zählrahte in 1/" + str(time) + "s")
    axis.set_title("Röntgenspektrum")
    canvas = FigureCanvas(figure)
    sw.add(canvas)
    sw.show_all()

    if filename != "":
        figure.savefig(filename)
コード例 #20
0
ファイル: heatmapV2.py プロジェクト: Earth13wells/Methane
									def __init__(self, lat, lon, alt, data, name):
										fig = Figure()
										self.ax = fig.gca(projection='3d')
										s = False
										for i in range(len(sys.argv)):
											if (sys.argv[i] == "-l"):
												try:
													self.ax.plot3D(latitude, longitude, altitude, sys.argv[i+1])
												except ValueError:
													print("Colour not recognized")
												except IndexError:
													print("Please input a colour")
											elif (sys.argv[i] == "-s"):
												s = True;
												try:
													self.ax.scatter(latitude, longitude, altitude, c=data, s=int(sys.argv[i+1]))
												except IndexError:
													print("Please input a point size")
										if (s != True):
											self.ax.scatter(latitude, longitude, altitude, c=data, s=1)
										self.ax.set_title("%s Heatmap" %name)
										self.ax.set_xlabel("x (m)")
										self.ax.set_ylabel("y (m)")
										self.ax.set_zlabel("altitude (m)")
										self.ax.view_init(30, 45)

										self.canvas = FigureCanvas(fig)
										self.canvas.set_size_request(800, 800)
    def __init__(self):

        #Readers should find it familiar, as we are creating a matplotlib figure here with a dpi(resolution) 100
        self.fig = Figure(figsize=(5, 5), dpi=100)
        #The axes element, here we indicate we are creating 1x1 grid and putting the subplot in the only cell
        #Also we are creating a polar plot, therefore we set projection as 'polar
        self.ax = self.fig.add_subplot(111, projection='polar')

        #Here, we borrow one example shown in the matplotlib gtk3 cookbook
        #and show a beautiful bar plot on a circular coordinate system
        self.theta = linspace(0.0, 2 * pi, 30, endpoint=False)
        self.radii = 10 * random.rand(30)
        self.width = pi / 4 * random.rand(30)
        self.bars = self.ax.bar(self.theta,
                                self.radii,
                                width=self.width,
                                bottom=0.0)

        #Here defines the color of the bar, as well as setting it to be transparent
        for r, bar in zip(self.radii, self.bars):
            bar.set_facecolor(cm.jet(r / 10.))
            bar.set_alpha(0.5)
        #Here we generate the figure
        self.ax.plot()

        #Creating Canvas which store the matplotlib figure
        self.canvas = FigureCanvas(self.fig)  # a Gtk.DrawingArea
コード例 #22
0
 def __init__(self, profile):
     self.profile = profile
     self.builder = Gtk.Builder()
     prog_path = Path(__file__).parent
     self.builder.add_from_file(str(prog_path / 'ui.glade'))
     self.builder.connect_signals(self)
     for obj in self.builder.get_objects():
         try:
             setattr(self, Gtk.Buildable.get_name(obj), obj)
         except:
             pass
     self.f = Figure()
     self.canvas = FigureCanvas(self.f)
     self.figure_holder.pack_start(self.canvas, True, True, 5)
     self.profile_data_x = [0]
     self.profile_data_y = [25]
     for (rate, target, time) in self.profile:
         t = (target - self.profile_data_y[-1]) / rate
         self.profile_data_x.append(self.profile_data_x[-1] + t)
         self.profile_data_y.append(target)
         self.profile_data_x.append(self.profile_data_x[-1] + time)
         self.profile_data_y.append(target)
     self.recorded_data_x = [0]
     self.recorded_data_y = [25]
     self.replot()
     self.stop_button.set_sensitive(False)
     self.start_button.set_sensitive(False)
     print(self.connect_button.get_label())
     self.main_window.show_all()
     self.oven = None
     self.running = False
     self.start_t = None
     GLib.idle_add(lambda: self.idle())
コード例 #23
0
ファイル: app_perceptron.py プロジェクト: ayumaru/IA_projetos
    def __init__(self):
        builder = Gtk.Builder()
        builder.add_from_file('app_perceptron_lib/main_gui.glade')
        builder.connect_signals(self)

        self.generator = DatasetGenerator()
        self.perceptron = Perceptron(run_perceptron)
        self.train_plotter = DataPlotter()
        self.train_canvas = FigureCanvas(self.train_plotter.fig)

        self.dataset_size_entry = builder.get_object('dataset_size_entry')
        self.max_epochs_entry = builder.get_object('max_epochs_entry')
        self.test_size_entry = builder.get_object('test_r_size_entry')
        self.learning_rate_entry = builder.get_object('learning_r_entry')
        self.epoch_output = builder.get_object('epoch_output')
        self.train_errors_output = builder.get_object('train_errors_output')
        self.test_errors_output = builder.get_object('test_errors_output')
        self.model_output = builder.get_object('model_output')

        self.gen_data_button = builder.get_object('gen_data_button')
        self.train_button = builder.get_object('train_button')
        self.test_button = builder.get_object('test_button')

        box = builder.get_object('graph_box')
        box.pack_start(self.train_canvas, True, True, 0)
        self.on_gen_data_button_clicked()

        window = builder.get_object('main_window')
        window.set_default_size(700, 550)
        window.show_all()
コード例 #24
0
    def __init__(self, app):

        Gtk.Window.__init__(self, application=app)
        self.set_default_size(800, 600)

        # ------------------------------------------------------------------

        # Functions to plot
        x = np.linspace(0, 5, 11)
        y = x**2

        # Figure as wrapper for plots
        fig = plt.figure()

        # Axes 1
        axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])
        axes.set_title("Bigger plot")

        # Plot1
        axes.plot(x, y)

        # Plot2
        axes.plot(y, x)

        # ------------------------------------------------------------------
        canvas = FigureCanvas(fig)
        canvas.set_size_request(400, 300)

        self.add(canvas)
コード例 #25
0
ファイル: pymark.py プロジェクト: RiedleroD/pymark
 def __init__(self):
     self.win = Gtk.Window()
     self.win.connect("delete-event", Gtk.main_quit)
     self.win.set_default_size(720, 480)
     self.fig = Figure(figsize=(10, 10), dpi=100)
     self.ax = self.fig.add_subplot()
     self.canvas = FigureCanvas(self.fig)
     sw = Gtk.ScrolledWindow()
     sw.set_border_width(10)
     sw.add(self.canvas)
     upperside = Gtk.ButtonBox(orientation=Gtk.Orientation.VERTICAL)
     self.fill_btnbox(upperside, TIMINGS)
     lowerside = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
     self.spin = Gtk.SpinButton()
     self.spin.set_range(1,
                         2**16)  #TODO: find out how to remove upper bound
     self.spin.set_increments(1, 10)
     self.spin.set_value(self.iterc)
     self.spin.connect("value-changed", self._on_spin)
     lowerside.pack_end(self.spin, False, True, 0)
     lowerside.pack_end(Gtk.Label.new("↓Iterations↓"), False, True, 0)
     self.progr2 = Gtk.ProgressBar()
     lowerside.pack_end(self.progr2, False, True, 2)
     self.progr1 = Gtk.ProgressBar()
     lowerside.pack_end(self.progr1, False, True, 2)
     sidebar = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
     sidebar.pack_start(upperside, False, True, 10)
     sidebar.pack_start(lowerside, True, True, 2)
     self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
     self.box.pack_start(sidebar, False, True, 2)
     self.box.pack_start(sw, True, True, 0)
     self.win.add(self.box)
     self.win.show_all()
     self.progr1.set_opacity(0)
     self.progr2.set_opacity(0)
コード例 #26
0
    def __init__(self):
        super(PlotWindow, self).__init__()
        self.connect('destroy', Gtk.main_quit)

        self.box = Gtk.Box(spacing=6, orientation=Gtk.Orientation(1))
        self.add(self.box)

        self.switch = Gtk.Switch()
        self.switch.connect("notify::active", self.on_switch_toggled)
        self.switch.set_active(False)
        self.box.pack_start(self.switch, True, True, 0)

        self.progress = Gtk.ProgressBar(show_text=True)
        self.box.pack_start(self.progress, True, True, 0)

        # global line, ax, canvas
        self.fig = Figure()
        self.ax = self.fig.add_subplot(111)
        self.ax.set_xlim(0, 30)
        self.ax.set_ylim([0, 255])
        self.ax.set_autoscale_on(False)
        self.data = []
        self.l_data, = self.ax.plot([], self.data, label='MagY')
        self.ax.legend()
        self.canvas = FigureCanvas(self.fig)
        self.canvas.set_size_request(800, 600)
        self.canvas.show()
        self.box.pack_start(self.canvas, True, True, 0)
        # self.line, = self.ax.plot([1, 2, 3], [1, 2, 10])

        port = '/dev/ttyACM0'
        baud = 9600
        self.arduino = ArdTest(self, port, baud)
コード例 #27
0
ファイル: history.py プロジェクト: khiemdoan/tsp-ga-pso
    def __init__(self, viewport):
        self._viewport = viewport

        figure = Figure()
        self._canvas = FigureCanvas(figure)
        self._viewport.add(self._canvas)
        self._viewport.show_all()
コード例 #28
0
def main():
    builder = Gtk.Builder()
    builder.add_objects_from_file(
        str(Path(__file__).parent / "mpl_with_glade3.glade"), ("window1", ""))
    builder.connect_signals(Window1Signals())
    window = builder.get_object("window1")
    sw = builder.get_object("scrolledwindow1")

    # Start of Matplotlib specific code
    figure = Figure(figsize=(8, 6), dpi=71)
    axis = figure.add_subplot(111)
    t = np.arange(0.0, 3.0, 0.01)
    s = np.sin(2 * np.pi * t)
    axis.plot(t, s)

    axis.set_xlabel('time [s]')
    axis.set_ylabel('voltage [V]')

    canvas = FigureCanvas(figure)  # a Gtk.DrawingArea
    canvas.set_size_request(800, 600)
    sw.add(canvas)
    # End of Matplotlib specific code

    window.show_all()
    Gtk.main()
コード例 #29
0
	def invoice_chart_clicked (self, button):
		global Figure
		if Figure == None:
			from matplotlib.figure import Figure
			from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
			from matplotlib.pyplot import pie
			self.figure = Figure(figsize=(4, 4), dpi=100)
			canvas = FigureCanvas(self.figure)  # a Gtk.DrawingArea
			canvas.set_size_request(800, 500)
			overlay = self.builder.get_object('overlay1')
			overlay.add (canvas)
		a = self.figure.add_subplot(111)
		labels = list()
		fractions = list()
		unpaid = 0
		self.cursor.execute("SELECT SUM(amount_due), c.name FROM invoices "
							"JOIN contacts AS c ON c.id = invoices.customer_id "
							"WHERE (canceled, paid, posted) = "
							"(False, False, True) GROUP BY customer_id, c.name "
							"ORDER BY SUM(amount_due)")
		for row in self.cursor.fetchall():
			customer_total = row[0]
			customer_name = row[1]
			fractions.append(customer_total)
			labels.append(customer_name)
			unpaid += 1
		if unpaid == 0:
			labels.append("None")
			fractions.append(1.00)
		a.pie(fractions, labels=labels, autopct='%1.f%%', radius=0.7)
		window = self.builder.get_object('window1')
		window.show_all()
コード例 #30
0
def makePlot(x_axis, y_axes, axis_update_callback, is_polar):
    if len(y_axes) < 1:
        raise Exception("Plot needs at least one y-axis")
    if is_polar and len(y_axes) != 1:
        displayError("Polar plots can't have more than one y-axis")
        y_axes = [y_axes[0]]
    fig = Figure(figsize=(5, 4), dpi=100)
    subplot = None
    if is_polar:
        subplot = fig.add_subplot(1, 1, 1, projection='polar')
    else:
        subplot = fig.add_subplot(1, 1, 1)

    #we need to adjust the plot so that we have enough space for extra labels
    if len(y_axes) > 2:
        fig.subplots_adjust(right=0.75)
    #generate all axes
    subplots = [subplot]
    for axis in y_axes[1:]:
        subplots.append(subplot.twinx())

    #set labels, etc
    i = -1
    for axis, plot in zip(y_axes, subplots):
        axis.setUpdateCallback(axis_update_callback)
        if not is_polar:
            plot.set_ylabel("%s [%s]" % (axis.name, str(axis.unit)))
        else:
            label_position = plot.get_rlabel_position()
            plot.text(np.radians(label_position + 10),
                      plot.get_rmax() / 2.0,
                      "%s [%s]" % (axis.name, str(axis.unit)),
                      rotation=label_position,
                      ha='center',
                      va='center')
        if axis.min_val is None and axis.max_val is None:
            plot.set_ylim(auto=True)
        else:
            plot.set_ylim(axis.min_val, axis.max_val)
        if i >= 0:
            plot.spines['right'].set_position(('outward', i * 60))
        i += 1

    subplot.set_xlabel("%s [%s]" % (x_axis.name, str(x_axis.unit)))
    if x_axis.min_val is None and x_axis.max_val is None:
        subplot.set_xlim(auto=True)
    else:
        subplot.set_xlim(x_axis.min_val, x_axis.max_val)
    subplot.grid(True)

    canvas = FigureCanvas(fig)
    canvas.set_size_request(600, 600)
    box = Gtk.VBox()
    toolbar = NavigationToolbar(canvas, box)

    box.pack_start(canvas, False, False, 0)
    box.pack_start(toolbar, False, False, 0)

    return box, canvas, subplots
コード例 #31
0
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(600, 600)
        self.connect('destroy', lambda win: Gtk.main_quit())

        self.set_title('GtkListStore demo')
        self.set_border_width(8)

        vbox = Gtk.VBox(False, 8)
        self.add(vbox)

        label = Gtk.Label('Double click a row to plot the data')

        vbox.pack_start(label, False, False, 0)

        sw = Gtk.ScrolledWindow()
        sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        sw.set_policy(Gtk.PolicyType.NEVER,
                      Gtk.PolicyType.AUTOMATIC)
        vbox.pack_start(sw, True, True, 0)

        model = self.create_model()

        self.treeview = Gtk.TreeView(model)
        self.treeview.set_rules_hint(True)

        # matplotlib stuff
        fig = Figure(figsize=(6, 4))

        self.canvas = FigureCanvas(fig)  # a Gtk.DrawingArea
        vbox.pack_start(self.canvas, True, True, 0)
        ax = fig.add_subplot(111)
        self.line, = ax.plot(self.data[0, :], 'go')  # plot the first row

        self.treeview.connect('row-activated', self.plot_row)
        sw.add(self.treeview)

        self.add_columns()

        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.KEY_PRESS_MASK |
                        Gdk.EventMask.KEY_RELEASE_MASK)
コード例 #32
0
class DataManager(Gtk.Window):
    numRows, numCols = 20, 10

    data = random((numRows, numCols))

    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(600, 600)
        self.connect('destroy', lambda win: Gtk.main_quit())

        self.set_title('GtkListStore demo')
        self.set_border_width(8)

        vbox = Gtk.VBox(False, 8)
        self.add(vbox)

        label = Gtk.Label('Double click a row to plot the data')

        vbox.pack_start(label, False, False, 0)

        sw = Gtk.ScrolledWindow()
        sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        sw.set_policy(Gtk.PolicyType.NEVER,
                      Gtk.PolicyType.AUTOMATIC)
        vbox.pack_start(sw, True, True, 0)

        model = self.create_model()

        self.treeview = Gtk.TreeView(model)
        self.treeview.set_rules_hint(True)

        # matplotlib stuff
        fig = Figure(figsize=(6, 4))

        self.canvas = FigureCanvas(fig)  # a Gtk.DrawingArea
        vbox.pack_start(self.canvas, True, True, 0)
        ax = fig.add_subplot(111)
        self.line, = ax.plot(self.data[0, :], 'go')  # plot the first row

        self.treeview.connect('row-activated', self.plot_row)
        sw.add(self.treeview)

        self.add_columns()

        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.KEY_PRESS_MASK |
                        Gdk.EventMask.KEY_RELEASE_MASK)

    def plot_row(self, treeview, path, view_column):
        ind, = path  # get the index into data
        points = self.data[ind, :]
        self.line.set_ydata(points)
        self.canvas.draw()

    def add_columns(self):
        for i in range(self.numCols):
            column = Gtk.TreeViewColumn(str(i), Gtk.CellRendererText(), text=i)
            self.treeview.append_column(column)

    def create_model(self):
        types = [float]*self.numCols
        store = Gtk.ListStore(*types)

        for row in self.data:
            store.append(tuple(row))
        return store