Exemple #1
0
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        # simulation_figure = plt.figure(figsize=(7, 7))
        # membrane_axis = simulation_figure.add_subplot(311)
        figure, (self.membrane_axis, self.conductance_axis, self.gate_axis) = \
        plt.subplots(3, 1, gridspec_kw={'height_ratios': [3, 2, 2]}, figsize=(7, 11))

        self.membrane_axis.set_ylabel("Membrane potential (mV)",
                                      fontsize=AXIS_LABEL_SIZE)
        self.membrane_axis.set_ylim([-30, 120])
        self.current_axis = self.membrane_axis.twinx()
        self.current_axis.set_ylabel("Input current (uA/cm2)")
        self.current_axis.set_ylim([-20, 100])

        # conductance_axis = simulation_figure.add_subplot(312)
        self.conductance_axis.set_ylabel("Conductance (mS/cm\u00b2)",
                                         fontsize=AXIS_LABEL_SIZE)

        # gate_axis = simulation_figure.add_subplot(313)
        self.gate_axis.set_ylabel("fraction of channels",
                                  fontsize=AXIS_LABEL_SIZE)
        self.gate_axis.legend(("m gate", "h gate", "n gate"),
                              loc="lower right",
                              prop=font_gate_legend,
                              frameon=False,
                              borderpad=0,
                              handletextpad=0,
                              labelspacing=0)

        self.canvas = FigureCanvasTkAgg(figure, master=self)
        print(figure)
        print(self)
        toolbar = NavToolbar(self.canvas, self)
        toolbar.pack(side=tk.BOTTOM)

        self.canvas.draw()
        self.canvas.get_tk_widget().pack(fill=tk.BOTH, expand=1)
        figure.tight_layout()
        self.plot_first = False
        self.lines = [None, None, None, None, None, None, None, None]
Exemple #2
0
class GraphFrame(tk.Frame):
    def __init__(self, master_frame, data: sensor_node_data.SensorHubData,
                 type):
        tk.Frame.__init__(self, master=master_frame)
        self.config(bg='white')
        self.plotted_lines = [
        ]  # type: list # to hold lines to update with new data
        self.data = data
        self.figure_bed = plt.figure(figsize=FIGURE_SIZE)
        self.axis = plt.subplot(111)
        x_format = mdates.DateFormatter("%H:%M")
        # self.figure_bed.autofmt_xdate()
        self.axis.xaxis.set_major_formatter(x_format)
        self.axis.format_coord = lambda x, y: ""  # remove the coordinates in the toolbox

        # set the limits of the frame
        start_time = datetime.now()

        self.axis.set_xlim([
            start_time - timedelta(minutes=15),
            start_time + timedelta(minutes=5)
        ])
        if type == 'Temperature':
            self.axis.set_ylim([15, 100])

        self.axis.set_xlabel("Time", fontsize=12)
        self.axis.set_ylabel(type, fontsize=12)

        self.canvas = FigureCanvasTkAgg(self.figure_bed, master=self)
        self.canvas._tkcanvas.config(highlightthickness=0)
        toolbox_frame = tk.Frame(self)
        toolbox_frame.pack(side=tk.BOTTOM)
        self.toolbar = NavToolbar(self.canvas, toolbox_frame)
        self.toolbar.pack(side=tk.BOTTOM)

        self.canvas.draw()
        self.canvas.get_tk_widget().pack(side='left', fill=tk.BOTH, expand=1)
        self.lines = [None, None, None]

    def update(self):
        # print('lines: ', self.lines)
        # print('num_data points = ', self.data.sensors[0].plot_index)
        for i, line in enumerate(self.lines):
            data_end = self.data.sensors[i].plot_index
            time_series = self.data.sensors[i].time_series[:data_end]
            color_series = self.data.sensors[i].color_index[:data_end]
            # print("color series: ", i, color_series)
            if self.lines[i]:
                # print('setind data: ', time_series)
                line.set_ydata(color_series)
                line.set_xdata(time_series)
                # print('set data: ', color_series)
                # print(time_series)
            else:
                new_line, = self.axis.plot(time_series, color_series)
                self.lines[i] = new_line  # TODO: does line = new_line work
        self.axis.relim()
        self.axis.autoscale_view(True, True, True)
        now = datetime.now()

        self.axis.set_xlim(
            [now - timedelta(minutes=15), now + timedelta(minutes=5)])
        # self.axis.set_ylim([np.amin(color_series), now + timedelta(minutes=5)])
        if color_series.any():
            print('y min:', np.amin(color_series))
            print('y max:', np.amax(color_series))
        self.canvas.draw()

    def update_old(self):
        print("update")
        if self.data.sensors[0].current_index == 0:
            return  # no data
        data_end0 = self.data.sensors[0].current_index - 1
        data_end1 = self.data.sensors[1].current_index - 1
        print('indexes: ', data_end0, data_end1)
        t_series1 = self.data.sensors[0].raw_color_data['time'][:data_end0]
        t_series2 = self.data.sensors[1].raw_color_data['time'][:data_end1]
        # t_series3 = self.data.sensors[2].raw_color_data['time']
        color_series1 = self.data.sensors[0].color_index[:data_end0]
        color_series2 = self.data.sensors[1].color_index[:data_end1]
        # color_series3 = self.data.sensors[2].color_index

        print('time1: ', t_series1)
        print('data1: ', color_series1)
        if self.line1:
            self.line1.set_ydata(color_series1)
            self.line1.set_xdata(t_series1)
        else:
            self.line1, = self.axis.plot(t_series1, color_series1)

        if self.line2:
            self.line2.set_ydata(color_series1)
            self.line2.set_xdata(t_series1)
        else:
            self.line2, = self.axis.plot(t_series1, color_series1)
        print(self.line1)
        self.axis.relim()
        self.axis.autoscale_view(True, True, True)
        self.canvas.draw()