Exemple #1
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.label_options = {'color': rgb('#000000'), 'bold': True}
     self.background_color = rgb('f8f8f2')
     self.tick_color = rgb('808080')
     self.border_color = rgb('808080')
     self.xlabel = 'X'
     self.ylabel = 'Y'
     self.x_ticks_minor = 5
     self.x_ticks_major = 25
     self.y_ticks_major = 1
     self.y_grid_label = True
     self.x_grid_label = True
     self.padding = 5
     self.x_grid = True
     self.y_grid = True
     self.xmin = -0
     self.xmax = 100
     self.ymin = -1
     self.ymax = 1
     self.i = 1
     self.stop = False
     self.plot = MeshLinePlot(color=[0, 0, 0.75, 1])
     self.plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
     self.add_plot(self.plot)
     Thread(target=self.redraw).start()
Exemple #2
0
    def graph_create(self):
        global graph1
        graph1 = Graph(
            label_options={'color': rgb('001933'), 'bold': True},
            background_color=rgb('f8f8f2'),
            tick_color=rgb('001933'),
            border_color=rgb('808080'),
            xlabel='X',
            ylabel='Y',
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            x_ticks_major=5,
            y_ticks_major=0.2,
            x_grid=True,
            y_grid=True,
            xmin=-0,
            xmax=30,
            ymin=-1,
            ymax=1)

        k = np.random.normal()
        global plot1
        plot1 = MeshLinePlot(color=[0, 0, 0.75, 1])
        y = (0.5 - 0.2)/30*np.linspace(0, max_year-1, max_year) + 0.2*np.ones(max_year) + np.random.normal(0, 0.05, max_year)
        plot1.points = [(x, y[x]) for x in range(0, 30)]
        graph1.add_plot(plot1)
        self.add_widget(graph1)
        return graph1
Exemple #3
0
    def init(self):
        # use kivy garden's graph widget
        graph = Graph(
            xlabel='t',
            ylabel='HFR',
            x_ticks_minor=5,
            x_ticks_major=10,
            y_ticks_minor=1,
            y_ticks_major=5,
            y_grid_label=True,
            x_grid_label=False,
            padding=0,
            y_grid=False,
            x_grid=False,
            xmin=0,
            ymin=0,
            xmax=100,
            ymax=30,
            _with_stencilbuffer=False,  # or it does not work in ScreenManager
            label_options={'color': rgb('808080')})
        y = (float(i) for i in range(50))
        x = (float(i) for i in range(50))
        plot = MeshLinePlot(color=rgb('1100aa'))
        pts = list(zip(x, y))
        plot.points = pts
        graph.add_plot(plot)

        self.ids.plot.add_widget(graph)

        self.plot = plot
        self.graph = graph
Exemple #4
0
    def create_plot(self):
        x2 = self.x2_variable
        plot = self.plot
        if plot is not None:
            if (x2 and isinstance(plot, ContourPlot)
                    or not x2 and isinstance(plot, LinePlot)):
                return
            self.graph.remove_plot(plot)

        for plot in self._contour_plots:
            self.graph.remove_plot(plot)
            self._contour_plots = []

        self._yvals = None
        yvar = x2 or self.y_variable
        graph_theme = {
            'label_options': {
                'color': rgb('444444'),
                'bold': True
            },
            # 'background_color': rgb('f8f8f2'),
            'tick_color':
            rgb('808080'),
            'border_color':
            rgb('808080'),
            'xlabel':
            '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(self.x_variable,
                                                       self.x_variable)),
            'ylabel':
            self.formula.variable_descriptions.get(yvar, yvar),
            'x_ticks_minor':
            5,
            # 'y_ticks_minor': 5,
            'y_grid_label':
            True,
            'x_grid_label':
            True,
            'padding':
            5,
            'x_grid':
            True,
            'y_grid':
            True,
        }

        graph = self.graph
        for k, v in graph_theme.items():
            setattr(graph, k, v)

        if x2:
            self.plot = plot = ContourPlot(color=next(self.colors))
        else:
            self.plot = plot = LinePlot(color=next(self.colors), line_width=2)
        graph.add_plot(plot)

        self._value_plot = PointPlot(color=next(self.colors), point_size=3)
        graph.add_plot(self._value_plot)
Exemple #5
0
 def __init__(self, *args, **kwargs):
     super(PlotScreen, self).__init__(*args, **kwargs)
     self.graph_figure = None
     self.colors = itertools.cycle(
         [rgb('7dac9f'),
          rgb('dc7062'),
          rgb('66a8d4'),
          rgb('e5b060')])
Exemple #6
0
    def graphy(self):

        graph_theme = {'label_options': {'color': rgb('595959'), 'bold': False}, 'background_color': rgb('DBE49A'),
                       'tick_color': rgb('999999'), 'border_color': rgb('808080')}

        self.graph = CustomGraph(pos=(self.width-dp(410), self.height - dp(347)), size_hint = (None, None),
                                 size = (dp(410), dp(300)), xlabel='Time', ylabel=self.title, x_ticks_minor=5,
                                 x_ticks_major=30, y_ticks_major=self.y_tick, y_grid_label=True, x_grid_label=True,
                                 padding=10, xlog=False, ylog=False, x_grid=True, y_grid=True, xmin=0,
                                 xmax=self.ids.fourbar.max_time, ymin=self.y_min, ymax=self.y_max, draw_border = True,
                                 **graph_theme)
Exemple #7
0
 def check_water_temp(self, *args):
     if self.water_temp_is >= self.water_temp_max:
         if self.water_alarm_counter == 5:
             self.water_alarm_counter = 0
             if self.water_alarm:
                 self.graph_water.background_color = rgb('ffffff')
                 self.water_alarm = False
             else:
                 self.graph_water.background_color = rgb('ff0000')
                 self.water_alarm = True
         self.water_alarm_counter += 1
     else:
         self.graph_water.background_color = rgb('ffffff')
Exemple #8
0
 def check_water_temp(self, *args):
     if self.water_temp_is >= self.water_temp_max:
         if self.water_alarm_counter == 5:
             self.water_alarm_counter = 0
             if self.water_alarm:
                 self.graph_water.background_color = rgb('ffffff')
                 self.water_alarm = False
             else:
                 self.graph_water.background_color = rgb('ff0000')
                 self.water_alarm = True
         self.water_alarm_counter += 1
     else:
         self.graph_water.background_color = rgb('ffffff')
Exemple #9
0
    def create_plot(self):
        x2 = self.x2_variable
        plot = self.plot
        if plot is not None:
            if (x2 and isinstance(plot, ContourPlot)
                    or not x2 and isinstance(plot, LinePlot)):
                return
            self.graph.remove_plot(plot)

        for plot in self._contour_plots:
            self.graph.remove_plot(plot)
            self._contour_plots = []

        self._yvals = None
        yvar = x2 or self.y_variable
        graph_theme = {
            'label_options': {
                'color': rgb('444444'),
                'bold': True},
            #'background_color': rgb('f8f8f2'),
            'tick_color': rgb('808080'),
            'border_color': rgb('808080'),
            'xlabel': '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(
                    self.x_variable, self.x_variable)),
            'ylabel': self.formula.variable_descriptions.get(
                yvar, yvar),
            'x_ticks_minor': 5,
            #'y_ticks_minor': 5,
            'y_grid_label': True,
            'x_grid_label': True,
            'padding': 5,
            'x_grid': True,
            'y_grid': True,
        }

        graph = self.graph
        for k, v in graph_theme.items():
            setattr(graph, k, v)

        if x2:
            self.plot = plot = ContourPlot(color=next(self.colors))
        else:
            self.plot = plot = LinePlot(color=next(self.colors), line_width=2)
        graph.add_plot(plot)

        self._value_plot = PointsPlot(color=next(self.colors), point_size=3)
        graph.add_plot(self._value_plot)
 def regen_plot(self):
     scalingMap = self.scaling_map
     
     graphContainer = self.ids.graphcontainer
     graphContainer.clear_widgets()
     
     graph = AnalogScaler()
     graphContainer.add_widget(graph)
     
     plot = LinePlot(color=rgb('00FF00'), line_width=1.25)
     graph.add_plot(plot)
     self.plot = plot
             
     points = []
     map_size = self.map_size
     max_scaled = None
     min_scaled = None
     for i in range(map_size):
         volts = scalingMap.getVolts(i)
         scaled = scalingMap.getScaled(i)
         points.append((volts, scaled))
         if max_scaled == None or scaled > max_scaled:
             max_scaled = scaled
         if min_scaled == None or scaled < min_scaled:
             min_scaled = scaled
         
     graph.ymin = min_scaled
     graph.ymax = max_scaled
     graph.xmin = 0
     graph.xmax = 5
     plot.points = points
Exemple #11
0
    def init(self, octoprint):
        self.octoprint = octoprint
        # use kivy garden's graph widget
        graph = Graph(
            xlabel='',
            ylabel='°C',
            x_ticks_minor=5,
            x_ticks_major=25,
            y_ticks_minor=0,
            y_ticks_major=50,
            y_grid_label=True,
            x_grid_label=False,
            padding=5,
            y_grid=True,
            xmax=len(self.hotend_temps),
            ymax=230,
            _with_stencilbuffer=False,  # or it does not work in ScreenManager
            label_options={'color': rgb('000000')})
        self.hotend_plot = MeshLinePlot(color=[1, 0, 0, 1])
        self.bed_plot = MeshLinePlot(color=[0, 0, 1, 1])
        graph.add_plot(self.hotend_plot)
        graph.add_plot(self.bed_plot)

        self.ids.plot.add_widget(graph)
        self.graph = graph
        self.update_plot()

        self.status = "Ready."
    def _regen_plot_interpolated(self, volts, scaled):
        graphContainer = self.ids.graphcontainer
        graphContainer.clear_widgets()

        graph = AnalogScaler()
        graphContainer.add_widget(graph)

        plot = LinePlot(color=rgb('00FF00'), line_width=1.25)
        graph.add_plot(plot)
        self.plot = plot

        points = []
        max_scaled = None
        min_scaled = None
        for i in range(ScalingMap.SCALING_MAP_POINTS):
            v = volts[i]
            s = scaled[i]
            points.append((v, s))
            if max_scaled == None or s > max_scaled:
                max_scaled = s
            if min_scaled == None or s < min_scaled:
                min_scaled = s

        graph.ymin = min_scaled
        graph.ymax = max_scaled
        graph.xmin = 0
        graph.xmax = 5
        plot.points = points
    def regen_plot2(self):
        scalingMap = self.scalingMap
        graph = kvFind(self, 'rcid', 'scalingGraph')

        plot = self.plot
        if not plot:
            plot = MeshLinePlot(color=rgb('FF0000'))
            graph.add_plot(plot)
            self.plot = plot

        points = []
        mapSize = self.mapSize
        maxScaled = None
        minScaled = None
        for i in range(mapSize):
            volts = scalingMap.getVolts(i)
            scaled = scalingMap.getScaled(i)
            points.append((volts, scaled))
            if maxScaled == None or scaled > maxScaled:
                maxScaled = scaled
            if minScaled == None or scaled < minScaled:
                minScaled = scaled

        graph.ymin = minScaled
        graph.ymax = maxScaled
        graph.xmin = 0
        graph.xmax = 5
        plot.points = points
    def regen_plot(self):
        scalingMap = self.scalingMap

        graphContainer = kvFind(self, 'rcid', 'graphcontainer')
        graphContainer.clear_widgets()

        graph = AnalogScaler()
        graphContainer.add_widget(graph)

        plot = MeshLinePlot(color=rgb('00FF00'))
        graph.add_plot(plot)
        self.plot = plot

        points = []
        mapSize = self.mapSize
        maxScaled = None
        minScaled = None
        for i in range(mapSize):
            volts = scalingMap.getVolts(i)
            scaled = scalingMap.getScaled(i)
            points.append((volts, scaled))
            if maxScaled == None or scaled > maxScaled:
                maxScaled = scaled
            if minScaled == None or scaled < minScaled:
                minScaled = scaled

        graph.ymin = minScaled
        graph.ymax = maxScaled
        graph.xmin = 0
        graph.xmax = 5
        plot.points = points
Exemple #15
0
    def regen_plot(self):
        scalingMap = self.scaling_map

        graphContainer = self.ids.graphcontainer
        graphContainer.clear_widgets()

        graph = AnalogScaler()
        graphContainer.add_widget(graph)

        plot = LinePlot(color=rgb('00FF00'), line_width=1.25)
        graph.add_plot(plot)
        self.plot = plot

        points = []
        map_size = self.map_size
        max_scaled = None
        min_scaled = None
        for i in range(map_size):
            volts = scalingMap.getVolts(i)
            scaled = scalingMap.getScaled(i)
            points.append((volts, scaled))
            if max_scaled == None or scaled > max_scaled:
                max_scaled = scaled
            if min_scaled == None or scaled < min_scaled:
                min_scaled = scaled

        graph.ymin = min_scaled
        graph.ymax = max_scaled
        graph.xmin = 0
        graph.xmax = 5
        plot.points = points
Exemple #16
0
    def _regen_plot_interpolated(self, volts, scaled):
        graphContainer = self.ids.graphcontainer
        graphContainer.clear_widgets()

        graph = AnalogScaler()
        graphContainer.add_widget(graph)

        plot = LinePlot(color=rgb('00FF00'), line_width=1.25)
        graph.add_plot(plot)
        self.plot = plot

        points = []
        max_scaled = None
        min_scaled = None
        for i in range(ScalingMap.SCALING_MAP_POINTS):
            v = volts[i]
            s = scaled[i]
            points.append((v, s))
            if max_scaled == None or s > max_scaled:
                max_scaled = s
            if min_scaled == None or s < min_scaled:
                min_scaled = s

        graph.ymin = min_scaled
        graph.ymax = max_scaled
        graph.xmin = 0
        graph.xmax = 5
        plot.points = points
Exemple #17
0
    def create_kivy_plot(self,
                         series=np.array(range(12)),
                         label_y='Average Response Time'):
        if self.graph_figure:
            self.destroy()

        series_len = len(series)
        if series_len == 0:
            return False
        max_y = max(series)
        min_y = min(series)
        #arg_max_y = series.index(max_y) # use this to label max and min...
        #arg_min_y = series.index(min_y) # with their resp time stamp
        ticks_y = round(max_y / 10., 2)

        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True
            },
            'background_color': rgb('000000'),  # back ground color of canvas
            'tick_color': rgb('444444'),  # ticks and grid
            'border_color': rgb('444444')
        }  # border drawn around each graph

        self.graph_figure = Graph(xlabel='Last {} games'.format(series_len),
                                  ylabel=label_y,
                                  x_ticks_minor=5,
                                  x_ticks_major=5,
                                  y_ticks_major=ticks_y,
                                  y_grid_label=True,
                                  x_grid_label=True,
                                  padding=10,
                                  x_grid=False,
                                  y_grid=True,
                                  xmin=0,
                                  xmax=series_len,
                                  ymin=0,
                                  ymax=int(1.2 * max_y + 1),
                                  _with_stencilbuffer=False,
                                  **graph_theme)
        plot = SmoothLinePlot(color=next(self.colors))  #mode='line_strip',
        plot.points = [(x, series[x - 1]) for x in range(1, len(series) + 1)]
        self.graph_figure.add_plot(plot)

        self.add_widget(self.graph_figure)
    def __init__(self):
        self.graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True
            },
            'background_color': rgb('b8b7bb'),  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')
        }  # border drawn around each graph
        self.graph_canvas = BoxLayout(orientation='vertical', padding=5)
        self.graph_rain = Graph(ylabel="rainfall(mm/s)",
                                y_grid_label=True,
                                x_grid_label=True,
                                xmin=0,
                                xmax=10,
                                ymin=0,
                                ymax=5000,
                                x_ticks_major=5,
                                y_ticks_major=2500,
                                x_ticks_minor=1,
                                y_ticks_minor=100,
                                x_grid=True,
                                y_grid=True,
                                padding=5,
                                **self.graph_theme)

        self.graph_temp = Graph(ylabel="temperature (C)",
                                y_grid_label=True,
                                x_grid_label=True,
                                xmin=0,
                                xmax=10,
                                ymin=0,
                                ymax=50,
                                x_ticks_major=5,
                                y_ticks_major=25,
                                x_ticks_minor=1,
                                y_ticks_minor=5,
                                x_grid=True,
                                y_grid=True,
                                padding=5,
                                **self.graph_theme)

        self.plot_rain = MeshLinePlot(color=[0, 0, 1, 1])
        self.plot_temp = MeshLinePlot(color=[1, 0, 0, 1])
 def get_color(self, key):
     color = self.color_map.get(key)
     if not color:
         index = self.color_index
         color = rgb(self.colors[index])
         index = index + 1 if index < len(self.colors) - 1 else 0
         self.color_index = index
         self.color_map[key] = color
     return color
 def get_color(self, key):
     color = self.color_map.get(key)
     if not color:
         index = self.color_index
         color = rgb(self.colors[index])
         index = index + 1 if index < len(self.colors) - 1 else 0
         self.color_index = index
         self.color_map[key] = color
     return color
Exemple #21
0
    def build(self):
        b = BoxLayout(orientation='vertical')
        self.title = "Moving Sine Wave"

        # example of a custom theme
        colors = itertools.cycle(
            [rgb('7dac9f'),
             rgb('dc7062'),
             rgb('66a8d4'),
             rgb('e5b060')])
        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True
            },
            'background_color': rgb('f8f8f2'),  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')
        }  # border drawn around each graph

        graph = Graph(xlabel='t',
                      ylabel='Y=sin(wt+a)',
                      x_ticks_minor=5,
                      x_ticks_major=25,
                      y_ticks_major=1,
                      y_grid_label=True,
                      x_grid_label=True,
                      padding=5,
                      xlog=False,
                      ylog=False,
                      x_grid=True,
                      y_grid=True,
                      xmin=-50,
                      xmax=50,
                      ymin=-1,
                      ymax=1,
                      **graph_theme)

        plot = MeshLinePlot(color=next(colors))
        plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
        graph.add_plot(plot)
        self.plot = plot  # this is the moving graph, so keep a reference

        plot2 = MeshLinePlot(color=next(colors))
        plot2.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
        graph.add_plot(plot2)
        self.plot2 = plot2

        Clock.schedule_interval(self.update_points, 1 / 60.)

        b.add_widget(graph)

        return b
Exemple #22
0
        def build(self):

            # example of a custom theme
            colors = itertools.cycle(
                [rgb('7dac9f'),
                 rgb('dc7062'),
                 rgb('66a8d4'),
                 rgb('e5b060')])
            graph_theme = {
                'label_options': {
                    'color': rgb('444444'),
                    'bold': True
                },
                'background_color': rgb('f8f8f2'),
                'tick_color': rgb('808080'),
                'border_color': rgb('808080')
            }

            graph = Graph(xlabel='Cheese',
                          ylabel='Apples',
                          x_ticks_minor=5,
                          x_ticks_major=25,
                          y_ticks_major=1,
                          y_grid_label=True,
                          x_grid_label=True,
                          padding=5,
                          xlog=False,
                          ylog=False,
                          x_grid=True,
                          y_grid=True,
                          xmin=-50,
                          xmax=50,
                          ymin=-1,
                          ymax=1,
                          **graph_theme)

            plot = SmoothLinePlot(color=next(colors))
            plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
            graph.add_plot(plot)

            plot = MeshLinePlot(color=next(colors))
            plot.points = [(x / 10., cos(x / 50.)) for x in range(-600, 501)]
            graph.add_plot(plot)
            self.plot = plot

            plot = MeshStemPlot(color=next(colors))
            graph.add_plot(plot)
            plot.points = [(x, x / 50.) for x in range(-50, 51)]

            Clock.schedule_interval(self.update_points, 1 / 60.)

            return graph
Exemple #23
0
    def build(self):
        b = BoxLayout(orientation='vertical')
        self.title = "Moving Sine Wave"

        # example of a custom theme
        colors = itertools.cycle([
            rgb('7dac9f'), rgb('dc7062'), rgb('66a8d4'), rgb('e5b060')])
        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True},
            'background_color': rgb('f8f8f2'),  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')}  # border drawn around each graph

        graph = Graph(
            xlabel='t',
            ylabel='Y=sin(wt+a)',
            x_ticks_minor=5,
            x_ticks_major=25,
            y_ticks_major=1,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            xlog=False,
            ylog=False,
            x_grid=True,
            y_grid=True,
            xmin=-50,
            xmax=50,
            ymin=-1,
            ymax=1,
            **graph_theme)


        plot = MeshLinePlot(color=next(colors))
        plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
        graph.add_plot(plot)
        self.plot = plot  # this is the moving graph, so keep a reference

        plot2 = MeshLinePlot(color=next(colors))
        plot2.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
        graph.add_plot(plot2)
        self.plot2 = plot2

        Clock.schedule_interval(self.update_points, 1 / 60.)

        b.add_widget(graph)

        return b
Exemple #24
0
    def create_graph(self):
        colors = itertools.cycle([
            rgb('7dac9f'), rgb('dc7062'), rgb('66a8d4'), rgb('e5b060')
        ])
        graph_theme = {
            'label_options': {
                'color': (0, 0, 0, 1),
                'bold': False},
            'background_color': (.9, .9, .9, 1),
            'tick_color': rgb('808080'),
            'border_color': rgb('808080')
        }
        graph = Graph(xlabel='',
                      ylabel='Glicemia',
                      font_size=14,
                      x_ticks_minor=0,
                      x_ticks_major=25,
                      y_ticks_major=1,
                      y_grid_label=True,
                      x_grid_label=True,
                      padding=5,
                      x_grid=True,
                      y_grid=True,
                      xmin=-0,
                      xmax=100,
                      ymin=-1,
                      ymax=1,
                      **graph_theme)

        #plot = MeshLinePlot(color=[1, 0, 0, 1])
        plot = MeshLinePlot(color=next(colors))
        plot.points = [(x, sin(x/10.)) for x in range(0, 101)]
        graph.add_plot(plot)
        return graph
Exemple #25
0
    def _initplot(self):
        self.label_options = {'color': rgb('#FF0000'), 'bold': True}
        self.background_color = rgb('f8f8f2')
        self.tick_color = rgb('808080')
        self.border_color = rgb('808080')
        self.xlabel = 'X'
        self.ylabel = 'Y'
        self.x_ticks_minor = 5
        self.x_ticks_major = 25
        self.y_ticks_major = 10
        self.y_grid_label = True
        self.x_grid_label = True
        self.padding = 5
        self.x_grid = True
        self.y_grid = True
        self.xmin = -0
        self.xmax = self._num_datapoints
        self.ymin = 20
        self.ymax = 80
        self.show_setpoint = True

        self.plot = LinePlot(color=[0, 0, 1, 1],
                             line_width=2)  # , color=[1, 0, 0, 1])
        x = [x for x in range(0, 101)]

        y = [random() for x in range(0, 101)]
        # self.plot.points  = [(x, random()) for x in range(0, 101)]
        plot_data = list(zip(x, self._temp))
        # plot_data = list(zip(self._time, self._temp))

        self.plot.points = plot_data
        self.add_plot(self.plot)

        if self.show_setpoint:
            self.setpoint_plot = LinePlot(
                color=[1, 0, 0, 1], line_width=2)  # , color=[1, 0, 0, 1])
            self.setpoint_plot.points = plot_data
            self.add_plot(self.setpoint_plot)
Exemple #26
0
        def build(self):

            # example of a custom theme
            colors = itertools.cycle([
                rgb('7dac9f'), rgb('dc7062'), rgb('66a8d4'), rgb('e5b060')])
            graph_theme = {
                'label_options': {
                    'color': rgb('444444'),
                    'bold': True},
                'background_color': rgb('f8f8f2'),
                'tick_color': rgb('808080'),
                'border_color': rgb('808080')}

            graph = Graph(
                    xlabel='Cheese',
                    ylabel='Apples',
                    x_ticks_minor=5,
                    x_ticks_major=25,
                    y_ticks_major=1,
                    y_grid_label=True,
                    x_grid_label=True,
                    padding=5,
                    xlog=False,
                    ylog=False,
                    x_grid=True,
                    y_grid=True,
                    xmin=-50,
                    xmax=50,
                    ymin=-1,
                    ymax=1,
                    **graph_theme)

            plot = SmoothLinePlot(color=next(colors))
            plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
            graph.add_plot(plot)

            plot = MeshLinePlot(color=next(colors))
            plot.points = [(x / 10., cos(x / 50.)) for x in range(-600, 501)]
            graph.add_plot(plot)
            self.plot = plot

            plot = MeshStemPlot(color=next(colors))
            graph.add_plot(plot)
            plot.points = [(x, x / 50.) for x in range(-50, 51)]

            Clock.schedule_interval(self.update_points, 1 / 60.)

            return graph
Exemple #27
0
    def _initplot(self):
        self.label_options = {'color': rgb('#FF0000'), 'bold': True}
        self.background_color = rgb('f8f8f2')
        self.tick_color = rgb('808080')
        self.border_color = rgb('808080')
        self.xlabel = 'X'
        self.ylabel = 'Y'
        self.x_ticks_minor = 5
        self.x_ticks_major = 25
        self.y_ticks_major = 1
        self.y_grid_label = True
        self.x_grid_label = True
        self.padding = 5
        self.x_grid = True
        self.y_grid = True
        self.xmin = -0
        self.xmax = 100
        self.ymin = -1
        self.ymax = 1

        self.plot = LinePlot(line_width=4, color=[1, 0, 0, 1])
        self.plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
        self.add_plot(self.plot)
Exemple #28
0
        def build(self):
            b = BoxLayout(orientation='vertical')
            # example of a custom theme
            colors = itertools.cycle(
                [rgb('7dac9f'),
                 rgb('dc7062'),
                 rgb('66a8d4'),
                 rgb('e5b060')])
            graph_theme = {
                'label_options': {
                    'color': rgb('444444'),  # color of tick labels and titles
                    'bold': True
                },
                'background_color':
                rgb('f8f8f2'),  # back ground color of canvas
                'tick_color': rgb('808080'),  # ticks and grid
                'border_color': rgb('808080')
            }  # border drawn around each graph

            graph1 = Graph(xlabel='500 samples/sec',
                           ylabel='Slave Velocity',
                           x_ticks_minor=5,
                           x_ticks_major=1000,
                           y_ticks_major=50000,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           xlog=False,
                           ylog=False,
                           x_grid=True,
                           y_grid=True,
                           xmin=-7500,
                           xmax=7500,
                           ymin=-125000,
                           ymax=125000,
                           **graph_theme)

            self.plot1 = MeshLinePlot(color=next(colors))
            self.plot2 = MeshLinePlot(color=next(colors))
            graph1.add_plot(self.plot1)
            graph1.add_plot(self.plot2)
            b.add_widget(graph1)
            Clock.schedule_interval(self.update_points, 1.0)
            return b
Exemple #29
0
    def render_graph(self):
        colors = itertools.cycle(
            [rgb('7dac9f'),
             rgb('dc7062'),
             rgb('66a8d4'),
             rgb('e5b060')])
        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True
            },
            'background_color': [0, 0, 0, 0.2],  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')
        }  # border drawn around each graph

        graph = Graph(xlabel=self.xlabel,
                      ylabel=self.ylabel,
                      x_ticks_minor=5,
                      x_ticks_major=25,
                      y_ticks_major=1,
                      y_grid_label=True,
                      x_grid_label=True,
                      padding=5,
                      xlog=False,
                      ylog=False,
                      x_grid=False,
                      y_grid=False,
                      xmin=self.xmin,
                      xmax=self.xmax,
                      ymin=self.ymin,
                      ymax=self.ymax,
                      **graph_theme)

        root_graph_layout = self.ids['root_graph']

        plot = BarPlot(color=next(colors), bar_spacing=.72)
        graph.add_plot(plot)
        plot.bind_to_graph(graph)
        plot.points = self.points
        root_graph_layout.add_widget(graph)
Exemple #30
0
    def __init__(self, **kwargs):
        super(HistoGraph, self).__init__(**kwargs)

        self.orientation = "vertical"
        self.size_hint = (1, 1)
        self._colors = itertools.cycle([
            rgb('ccff00'),
            rgb('e67e22'),
            rgb('8e44ad'),
            rgb('b7ff00'),
            rgb('f1c40f'),
            rgb('6C7A89'),
            rgb('34495e'),
            rgb('DB0A5B'),
            rgb('C8F7C5'),
            rgb('BFBFBF')
        ])

        self._graph_theme = {
            'label_options': {
                'color': rgb('99ccff'),  # color of tick labels and titles
                'bold': True
            },
            # #3B3C3D back ground color of canvas 738ffe
            'background_color': rgb('3B3C3D'),
            'tick_color': rgb('5588ff'),  # ticks and grid
            'border_color': rgb('5588ff')
        }  # border drawn around each graph

        self._agraph = Graph(xlabel=" ",
                             ylabel=" ",
                             x_ticks_minor=0,
                             x_ticks_major=1,
                             y_ticks_major=2,
                             y_grid_label=True,
                             x_grid_label=True,
                             padding=5,
                             xlog=False,
                             ylog=False,
                             x_grid=True,
                             y_grid=True,
                             xmin=0,
                             xmax=0,
                             ymin=0,
                             ymax=0,
                             **self._graph_theme)

        self.add_widget(self._agraph)
Exemple #31
0
    def make_layout(self):
        layout = BoxLayout(orientation="vertical")
        
        settingslayout = BoxLayout(orientation="horizontal")
        left_settings = BoxLayout(orientation="horizontal")
        settingslayout.add_widget(left_settings)
        
        
        on_off_layout = BoxLayout(orientation="vertical")
        self.on_off_layout = on_off_layout
        
        button_heating = Button(background_normal="pic/flame_off.png", background_down="pic/flame_pressed.png",allow_stretch=False, size_hint=(0.7, 1), border=[0,0,0,0])
        button_heating.bind(on_press=self.on_button_heating)
        self.button_heating = button_heating
        
        
        
        button_pump = Button(background_normal="pic/pump_off.png", background_down="pic/pump_pressed.png",allow_stretch=False, size_hint=(0.7, 1), border=[0,0,0,0])
        button_pump.bind(on_press=self.on_button_pump)
        self.button_pump = button_pump
        
        
        temperatur_panel = BoxLayout(orientation="vertical")
        
        oil_temp_label = Label(text = "0 Grad", color=[0,0,0,1], font_size = 30)
        self.oil_temp_label = oil_temp_label
        temperatur_panel.add_widget(oil_temp_label)
        
        water_temp_label = Label(text = "0 Grad", color=[0,0,0,1], font_size = 30)
        self.water_temp_label = water_temp_label
        temperatur_panel.add_widget(water_temp_label)
        
        time_label = Label(text = "0 min", color=[0,0,0,1], font_size = 30)
        self.time_label = time_label
        temperatur_panel.add_widget(time_label)
        
        heating_image = Image(source = 'pic/heating_off.png')
        self.heating_image = heating_image
        temperatur_panel.add_widget(heating_image)
        
        
        names_panel = BoxLayout(orientation="vertical")
        name_oil = Label(text = "Öl:", color=[0,0,0,1], font_size = 30)
        names_panel.add_widget(name_oil)
        name_water = Label(text = "Wasser:", color=[0,0,0,1], font_size = 30)
        names_panel.add_widget(name_water)
        name_time = Label(text = "Zeit:", color=[0,0,0,1], font_size = 30)
        names_panel.add_widget(name_time)
        name_heating = Label(text = "Heizen:", color=[0,0,0,1], font_size = 30)
        names_panel.add_widget(name_heating)
        
        
        
        set_value_panel = BoxLayout(orientation="vertical")
        set_value_oil_panel = BoxLayout(orientation="horizontal")
        set_value_water_panel = BoxLayout(orientation="horizontal")
        set_delta_heating_panel = BoxLayout(orientation="horizontal")
        set_delta_cooling_panel = BoxLayout(orientation="horizontal")
        set_value_panel.add_widget(set_value_oil_panel)
        set_value_panel.add_widget(set_value_water_panel)
        set_value_panel.add_widget(set_delta_heating_panel)
        set_value_panel.add_widget(set_delta_cooling_panel)
        
        
        set_oil_temp_slider = Slider(min = 0, max = 150, value = 50)
        self.set_oil_temp_slider = set_oil_temp_slider
        set_oil_temp_slider.bind(value=self.on_set_oil_temp_slider)
        set_value_oil_panel.add_widget(set_oil_temp_slider)
        set_oil_temp_label = Label(text = "50 °C", color=[0,0,0,1], font_size = 30, size_hint=(None,1))
        self.set_oil_temp_label = set_oil_temp_label
        set_value_oil_panel.add_widget(set_oil_temp_label)
        
        set_water_temp_slider = Slider(min = 0, max = 50, value = 10)
        self.set_water_temp_slider = set_water_temp_slider
        set_water_temp_slider.bind(value=self.on_set_water_temp_slider)
        set_value_water_panel.add_widget(set_water_temp_slider)
        set_water_temp_label = Label(text = "10 °C", color=[0,0,0,1], font_size = 30, size_hint=(None,1))
        self.set_water_temp_label = set_water_temp_label
        set_value_water_panel.add_widget(set_water_temp_label)
        
        name_delta_heating_label = Label(text = u"\u0394"+"Th", color=[0,0,0,1], font_size = 30, size_hint=(None,1))
        set_delta_heating_panel.add_widget(name_delta_heating_label)
        set_delta_heating_slider = Slider(min = 0, max = 10, value = 5)
        self.set_delta_heating_slider = set_delta_heating_slider
        set_delta_heating_slider.bind(value=self.on_set_delta_heating_slider)
        set_delta_heating_panel.add_widget(set_delta_heating_slider)
        set_delta_heating_label = Label(text = "5 °C", color=[0,0,0,1], font_size = 30, size_hint=(None,1))
        self.set_delta_heating_label = set_delta_heating_label
        set_delta_heating_panel.add_widget(set_delta_heating_label)
        
        name_delta_cooling_label = Label(text = u"\u0394"+"Tk", color=[0,0,0,1], font_size = 30, size_hint=(None,1))
        set_delta_cooling_panel.add_widget(name_delta_cooling_label)
        set_delta_cooling_slider = Slider(min = 0, max = 10, value = 5)
        self.set_delta_cooling_slider = set_delta_cooling_slider
        set_delta_cooling_slider.bind(value=self.on_set_delta_cooling_slider)
        set_delta_cooling_panel.add_widget(set_delta_cooling_slider)
        set_delta_cooling_label = Label(text = "5 °C", color=[0,0,0,1], font_size = 30, size_hint=(None,1))
        self.set_delta_cooling_label = set_delta_cooling_label
        set_delta_cooling_panel.add_widget(set_delta_cooling_label)
        
        
        
        
        left_settings.add_widget(on_off_layout)
        left_settings.add_widget(names_panel)
        left_settings.add_widget(temperatur_panel)
        settingslayout.add_widget(set_value_panel)
        on_off_layout.add_widget(button_heating)
        on_off_layout.add_widget(button_pump)
        layout.add_widget(settingslayout)
        
        
        
        with layout.canvas.before:
            Color(1, 1, 1, 1) 
            layout.rect = Rectangle(size=layout.size,
                           pos=layout.pos)
            
        layout.bind(pos=self.update_rect, size=self.update_rect)
        
        graph_theme = {
            'label_options':{
                'color':rgb('444444'), # color of tick labels and titles
                'bold':True}, 
            'background_color':rgb('ffffff'), # back ground color of canvas
            'tick_color':rgb('808080'), # ticks and grid
            'border_color':rgb('808080')}
        graph_oil = Graph( 
            xlabel="Zeit [s]",
            ylabel="Öltemperatur [°C]", 
            x_ticks_major=1, 
            y_ticks_major=1, 
            y_grid_label=True, 
            x_grid_label=True, 
            padding=5, 
            xlog=False, 
            ylog=False, 
            x_grid=True, 
            y_grid=True, 
            xmin=0, 
            xmax=10, 
            **graph_theme)
        self.graph_oil = graph_oil
        
        graph_water = Graph(
            xlabel="Zeit [s]", 
            ylabel="Wassertemperatur [°C]", 
            x_ticks_major=1, 
            y_ticks_major=10, 
            y_grid_label=True, 
            x_grid_label=True, 
            padding=5, 
            xlog=False, 
            ylog=False, 
            x_grid=True, 
            y_grid=True, 
            xmin=0, 
            xmax=10, 
            **graph_theme)
        self.graph_water = graph_water
        
        plot_oil = SmoothLinePlot(color=rgb('ff0000'))
        self.plot_oil = plot_oil
        
        plot_oil_set = SmoothLinePlot(color=rgb('00ff00'))
        self.plot_oil_set = plot_oil_set
        
        plot_water = SmoothLinePlot(color=rgb('0000ff'))
        self.plot_water = plot_water
        plot_water.points = [(x, x * x) for x in range(0, 11)]
        graph_oil.add_plot(plot_oil)
        graph_oil.add_plot(plot_oil_set)
        graph_water.add_plot(plot_water)
        layout.add_widget(graph_oil)
        layout.add_widget(graph_water)
        
        

        
        
        
        
        return layout
Exemple #32
0
        def build(self):
            b = BoxLayout(orientation='vertical')
            # example of a custom theme
            colors = itertools.cycle([
                rgb('7dac9f'), rgb('dc7062'), rgb('66a8d4'), rgb('e5b060')])
            graph_theme = {
                'label_options': {
                    'color': rgb('444444'),  # color of tick labels and titles
                    'bold': True},
                'background_color': rgb('f8f8f2'),  # back ground color of canvas
                'tick_color': rgb('808080'),  # ticks and grid
                'border_color': rgb('808080')}  # border drawn around each graph

            graph = Graph(
                xlabel='Cheese',
                ylabel='Apples',
                x_ticks_minor=5,
                x_ticks_major=25,
                y_ticks_major=1,
                y_grid_label=True,
                x_grid_label=True,
                padding=5,
                xlog=False,
                ylog=False,
                x_grid=True,
                y_grid=True,
                xmin=-50,
                xmax=50,
                ymin=-1,
                ymax=1,
                **graph_theme)

            plot = SmoothLinePlot(color=next(colors))
            plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
            # for efficiency, the x range matches xmin, xmax 
            graph.add_plot(plot)

            plot = MeshLinePlot(color=next(colors))
            plot.points = [(x / 10., cos(x / 50.)) for x in range(-500, 501)]
            graph.add_plot(plot)
            self.plot = plot  # this is the moving graph, so keep a reference

            plot = MeshStemPlot(color=next(colors))
            graph.add_plot(plot)
            plot.points = [(x, x / 50.) for x in range(-50, 51)]

            Clock.schedule_interval(self.update_points, 1 / 60.)

            graph2 = Graph(
                xlabel='Position (m)',
                ylabel='Time (s)',
                x_ticks_minor=0,
                x_ticks_major=1,
                y_ticks_major=10,
                y_grid_label=True,
                x_grid_label=True,
                padding=5,
                xlog=False,
                ylog=False,
                xmin=0,
                ymin=0,
                **graph_theme)
            b.add_widget(graph)

            if np is not None:
                (xbounds, ybounds, data) = self.make_contour_data()
                # This is required to fit the graph to the data extents
                graph2.xmin, graph2.xmax = xbounds
                graph2.ymin, graph2.ymax = ybounds

                plot = ContourPlot()
                plot.data = data
                plot.xrange = xbounds
                plot.yrange = ybounds
                plot.color = [1, 0.7, 0.2, 1]
                graph2.add_plot(plot)

                b.add_widget(graph2)
                self.contourplot = plot

                Clock.schedule_interval(self.update_contour, 1 / 60.)

            return b
Exemple #33
0
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.logger import Logger

# Kivy Garden
from kivy.garden.graph import Graph
from kivy.garden.graph import MeshLinePlot, SmoothLinePlot

###############################################################################
# Constants: Colors
###############################################################################

BACKGROUND_COLOR = [0, 0, 0, 1]
TEXT_COLOR = [1, 1, 1, 1]
TEXT_HIGHLIGHT_COLOR = rgb('ff0000')
AXIS_GREY = rgb('444444')
PLOT_BLUE = []
PLOT_GREEN = []
PLOT_RED = []
PLOT_YELLOW = []

###############################################################################
# Constants: Settings Data
###############################################################################

JSON_MATH = '''
[
	{
		"type": "options",
		"title": "Difficulty",
    def __init__(self, **kwargs):
        super(Screen, self).__init__(**kwargs)

        self.allowed_receive_database = True

        self.error = Image(
            source='Img/error.png',
            allow_stretch=False,
            keep_ratio=True,
            pos_hint={"center_x": 0.095, "center_y": 0.64},
            size_hint=(0.11, 0.11))

        self.wait = Image(
            source='Img/wait.png',
            allow_stretch=False,
            keep_ratio=True,
            pos_hint={"center_x": 0.095, "center_y": 0.64},
            size_hint=(0.11, 0.11))

        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True},
            'background_color': rgb('f8f8f2'),  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')}  # border drawn around each graph

        self.graph1 = Graph(
            xlabel='Time [s]',
            ylabel='Value',
            x_ticks_minor=5,
            x_ticks_major=5,
            y_ticks_minor=1,
            y_ticks_major=10,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            xlog=False,
            ylog=False,
            x_grid=False,
            y_grid=False,
            xmin=0,
            xmax=30,
            ymin=0,
            ymax=100,
            pos_hint={'center_x': 0.5, 'center_y': 0.5},
            _with_stencilbuffer=False,
            **graph_theme)

        self.graph2 = Graph(
            xlabel='Time [s]',
            ylabel='Value',
            x_ticks_minor=5,
            x_ticks_major=5,
            y_ticks_minor=1,
            y_ticks_major=1,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            xlog=False,
            ylog=False,
            x_grid=False,
            y_grid=False,
            xmin=0,
            xmax=30,
            ymin=-5,
            ymax=5,
            pos_hint={'center_x': 0.5, 'center_y': 0.5},
            _with_stencilbuffer=False,
            **graph_theme)

        self.plot1 = LinePlot(line_width=2, color=[1, 0, 0, 1])
        self.plot1.points = [(i, j*10/3) for i, j in enumerate(range(31))]
        self.graph1.add_plot(self.plot1)
        self.ids.panel1.add_widget(self.graph1)

        self.plot2 = LinePlot(line_width=2, color=[1, 0, 0, 1])
        self.plot2.points = [(i, j/3 - 5) for i, j in enumerate(range(31))]
        self.graph2.add_plot(self.plot2)
        self.ids.panel2.add_widget(self.graph2)
Exemple #35
0
import csv

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.utils import get_color_from_hex as rgb
TABLE_COLUMNS = 18
TABLE_ROWS = 10
ELEMENTS = []
ELEMENT_COLOR_MAP = {
    "Metalloids": rgb('77DD88'),
    "Nonmetals": rgb('22FF22'),
    "Halogens": rgb('22EECC'),
    "Noble gases": rgb('77CCFF'),
    "Alkali metals": rgb('FFCC33'),
    "Alkaline earth metals": rgb('FFFF44'),
    "Lanthanoids": rgb('FFBB99'),
    "Transition metals": rgb('DDBBBB'),
    "Post-transition metals": rgb('99DDCC'),
    "Actinoids": rgb('EEBBDD'),
}


def load_element_info():
    with open('element_properties.csv', 'r', encoding="ISO-8859-1") as f:
        elem_dict = csv.DictReader(f)
        list_elem_dict = list(elem_dict)
    return list_elem_dict

Exemple #36
0
        def build(self):
            b = BoxLayout(orientation='vertical')
            # example of a custom theme
            colors = itertools.cycle([
                rgb('7dac9f'), rgb('dc7062'), rgb('66a8d4'), rgb('e5b060')])
            graph_theme = {
                'label_options': {
                    'color': rgb('444444'),
                    'bold': True},
                'background_color': rgb('f8f8f2'),
                'tick_color': rgb('808080'),
                'border_color': rgb('808080')}

            graph = Graph(
                    xlabel='Cheese',
                    ylabel='Apples',
                    x_ticks_minor=5,
                    x_ticks_major=25,
                    y_ticks_major=1,
                    y_grid_label=True,
                    x_grid_label=True,
                    padding=5,
                    xlog=False,
                    ylog=False,
                    x_grid=True,
                    y_grid=True,
                    xmin=-50,
                    xmax=50,
                    ymin=-1,
                    ymax=1,
                    **graph_theme)


            plot = SmoothLinePlot(color=next(colors))
            plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
            graph.add_plot(plot)

            plot = MeshLinePlot(color=next(colors))
            plot.points = [(x / 10., cos(x / 50.)) for x in range(-600, 501)]
            graph.add_plot(plot)
            self.plot = plot

            plot = MeshStemPlot(color=next(colors))
            graph.add_plot(plot)
            plot.points = [(x, x / 50.) for x in range(-50, 51)]

            Clock.schedule_interval(self.update_points, 1 / 60.)


            graph2 = Graph(
                    xlabel='Position (m)',
                    ylabel='Time (s)',
                    x_ticks_minor=0,
                    x_ticks_major=1,
                    y_ticks_major=10,
                    y_grid_label=True,
                    x_grid_label=True,
                    padding=5,
                    xlog=False,
                    ylog=False,
                    xmin=0,
                    ymin=0,
                    **graph_theme)
            b.add_widget(graph)


            if np is not None:
                omega = 2 * pi / 30
                k = (2 * pi) / 2.0


                npoints = 100
                data = np.ones((npoints, npoints))

                position = [ii * 0.1 for ii in range(npoints)]
                time = [ii * 0.6 for ii in range(npoints)]

                for ii, t in enumerate(time):
                    for jj, x in enumerate(position):
                        data[ii, jj] = sin(k * x + omega * t) + sin(-k * x + omega * t)

                # This is required to fit the graph to the data extents
                graph2.xmax = max(position)
                graph2.ymax = max(time)

                plot = ContourPlot()
                plot.data = data
                plot.xrange = [min(position), max(position)]
                plot.yrange = [min(time), max(time)]
                plot.color = [1, 0.7, 0.2, 1]
                graph2.add_plot(plot)

                b.add_widget(graph2)

            return b
Exemple #37
0
class FormulaPlot(EventDispatcher):

    graph = ObjectProperty(None, rebind=True)

    plot = ObjectProperty()

    start = NumericProperty(0)

    end = NumericProperty(100)

    x2_start = NumericProperty(0)

    x2_end = NumericProperty(100)

    y_start = NumericProperty(0)

    y_end = NumericProperty(100)

    num_points = NumericProperty(100)

    formula = ObjectProperty(None, rebind=True)

    x_variable = StringProperty('')

    x2_variable = StringProperty('')

    x_variable_formula = ObjectProperty(None)

    x2_variable_formula = ObjectProperty(None)

    y_variable = StringProperty('')

    num_contours = NumericProperty(5)

    track_ylim = BooleanProperty(False)

    _last_values = {}

    _yvals = None

    _y_range = None

    _contour_plots = []

    _value_plot = None

    colors = itertools.cycle(
        [rgb('7dac9f'),
         rgb('dc7062'),
         rgb('66a8d4'),
         rgb('e5b060')])

    def __init__(self, **kwargs):
        super(FormulaPlot, self).__init__(**kwargs)
        self.fbind('start', self._update_from_params)
        self.fbind('end', self._update_from_params)
        self.fbind('x2_start', self._update_from_params)
        self.fbind('x2_end', self._update_from_params)
        self.fbind('num_points', self._update_from_params)
        self.fbind('x_variable', self._update_from_params)
        self.fbind('x2_variable', self._update_from_params)
        self.fbind('y_variable', self._update_from_params)
        self.fbind('formula', self._update_from_params)
        self.fbind('x_variable_formula', self._update_from_params)
        self.fbind('x2_variable_formula', self._update_from_params)

        self.fbind('y_start', self._update_y_vals)
        self.fbind('y_end', self._update_y_vals)
        self.fbind('num_contours', self._update_y_vals)

    def _update_from_params(self, *largs):
        self.refresh_plot(from_variables=False)

    def _update_y_vals(self, *largs):
        graph = self.graph
        if graph is None:
            return

        if self.x2_variable:
            if not self.plot or self._yvals is None:
                return
            self.plot.data = np.clip(self._yvals.T, self.y_start, self.y_end)
            self.compute_contours()
        else:
            graph.ymin = self.y_start
            graph.ymax = self.y_end
            graph.y_ticks_major = abs(graph.ymax - graph.ymin) / 4

    def compute_contours(self):
        graph = self.graph
        if graph is None or not self.x2_variable:
            return

        for plot in self._contour_plots:
            self.graph.remove_plot(plot)

        plots = self._contour_plots = []
        data = np.clip(self._yvals, self.y_start, self.y_end)
        xscale = (self.end - self.start) / self.num_points
        x2scale = (self.x2_end - self.x2_start) / self.num_points
        color = next(self.colors)

        for val in np.linspace(self.y_start, self.y_end, self.num_contours):
            contours = measure.find_contours(data, val)
            for contour in contours:
                contour[:, 0] *= xscale
                contour[:, 0] += self.start
                contour[:, 1] *= x2scale
                contour[:, 1] += self.x2_start

                plot = MeshLinePlot(color=color)
                plots.append(plot)
                graph.add_plot(plot)
                plot.points = contour

    def create_plot(self):
        x2 = self.x2_variable
        plot = self.plot
        if plot is not None:
            if (x2 and isinstance(plot, ContourPlot)
                    or not x2 and isinstance(plot, LinePlot)):
                return
            self.graph.remove_plot(plot)

        for plot in self._contour_plots:
            self.graph.remove_plot(plot)
            self._contour_plots = []

        self._yvals = None
        yvar = x2 or self.y_variable
        graph_theme = {
            'label_options': {
                'color': rgb('444444'),
                'bold': True
            },
            # 'background_color': rgb('f8f8f2'),
            'tick_color':
            rgb('808080'),
            'border_color':
            rgb('808080'),
            'xlabel':
            '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(self.x_variable,
                                                       self.x_variable)),
            'ylabel':
            self.formula.variable_descriptions.get(yvar, yvar),
            'x_ticks_minor':
            5,
            # 'y_ticks_minor': 5,
            'y_grid_label':
            True,
            'x_grid_label':
            True,
            'padding':
            5,
            'x_grid':
            True,
            'y_grid':
            True,
        }

        graph = self.graph
        for k, v in graph_theme.items():
            setattr(graph, k, v)

        if x2:
            self.plot = plot = ContourPlot(color=next(self.colors))
        else:
            self.plot = plot = LinePlot(color=next(self.colors), line_width=2)
        graph.add_plot(plot)

        self._value_plot = PointPlot(color=next(self.colors), point_size=3)
        graph.add_plot(self._value_plot)

    def refresh_plot(self, from_variables=True):
        if self.graph is None or not self.x_variable or not self.y_variable:
            return
        self.create_plot()

        formula = self.formula
        xvar = self.x_variable
        x2var = self.x2_variable
        # new_vals = {
        #     var: getattr(formula, var) for var in formula.x_variables
        #     if var != xvar and var != x2var}

        # if from_variables and new_vals == self._last_values:
        #     return
        # self._last_values = new_vals

        start = self.start
        end = self.end
        n = self.num_points
        plot = self.plot
        graph = self.graph
        self._yvals = None

        if x2var:
            x2_start = self.x2_start
            x2_end = self.x2_end

            xvals = np.linspace(start, end, n)
            xvals = np.repeat(np.expand_dims(xvals, 1), n, 1)

            x2vals = np.linspace(x2_start, x2_end, n)
            x2vals = np.repeat(np.expand_dims(x2vals, 1), n, 1).T

            input_variables = [(self.x_variable_formula, xvar),
                               (self.x2_variable_formula, x2var)]
            variables = {input_variables[0]: xvals, input_variables[1]: x2vals}

            yvals = formula.infer_variable_value(
                self.y_variable,
                variables,
                in_subtree={},
                input_variables=input_variables)
            if not isinstance(yvals,
                              np.ndarray) or n > 1 and yvals.shape != (n, n):
                yvals = np.zeros((n, n)) + float(yvals)
            else:
                yvals[np.logical_or(
                    np.logical_or(np.isnan(yvals), np.isinf(yvals)),
                    np.isneginf(yvals))] = -1000

            graph.xmin = start
            graph.xmax = end
            graph.ymin = x2_start
            graph.ymax = x2_end

            if self._y_range is None or self.track_ylim:
                self.y_start, self.y_end = self._y_range = \
                    float(np.min(yvals)), float(np.max(yvals))
            else:
                self._y_range = float(np.min(yvals)), float(np.max(yvals))

            graph.x_ticks_major = abs(end - start) / 10
            graph.y_ticks_major = abs(x2_end - x2_start) / 10
            graph.xlabel = '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(xvar, xvar))
            graph.ylabel = '{} -- {}'.format(
                self.x2_variable_formula.widget.name,
                self.formula.variable_descriptions.get(x2var, x2var))

            plot.xrange = (start, end)
            plot.yrange = (x2_start, x2_end)
            plot.data = np.clip(yvals.T, self.y_start, self.y_end)
            self._yvals = yvals

            self.compute_contours()
            self._value_plot.points = [(getattr(self.x_variable_formula, xvar),
                                        getattr(self.x2_variable_formula,
                                                x2var))]
        else:
            xvals = np.linspace(start, end, n)

            input_variables = [(self.x_variable_formula, xvar)]
            variables = {input_variables[0]: xvals}
            yvals = formula.infer_variable_value(
                self.y_variable,
                variables,
                in_subtree={},
                input_variables=input_variables)

            if not isinstance(
                    yvals,
                (np.ndarray, np.generic)) or n > 1 and len(yvals) == 1:
                yvals = np.zeros((n, )) + float(yvals)
            else:
                yvals[np.logical_or(
                    np.logical_or(np.isnan(yvals), np.isinf(yvals)),
                    np.isneginf(yvals))] = -1000

            ymin, ymax = np.min(yvals), np.max(yvals)
            if math.isclose(ymin, ymax):
                ydiff = abs(ymin) * 0.2
            else:
                ydiff = (ymax - ymin) * .02

            graph.xmin = start
            graph.xmax = end
            if self._y_range is None or self.track_ylim:
                self.y_start, self.y_end = self._y_range = \
                    float(ymin - ydiff), float(ymax + ydiff)
            else:
                self._y_range = float(ymin - ydiff), float(ymax + ydiff)
            graph.ymin = self.y_start
            graph.ymax = self.y_end

            graph.x_ticks_major = abs(end - start) / 10
            graph.y_ticks_major = abs(graph.ymax - graph.ymin) / 4
            graph.xlabel = '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(xvar, xvar))
            graph.ylabel = self.formula.variable_descriptions.get(
                self.y_variable, self.y_variable)

            plot.points = list(zip(xvals, yvals))
            self._value_plot.points = [(getattr(self.x_variable_formula, xvar),
                                        getattr(formula, self.y_variable))]

    def reset_y_axis(self):
        if not self.graph or not self.plot or self._y_range is None:
            return

        self.y_start, self.y_end = self._y_range
        def build(self):
            b = BoxLayout(orientation='vertical')
            # example of a custom theme
            colors = itertools.cycle(
                [rgb('7dac9f'),
                 rgb('dc7062'),
                 rgb('66a8d4'),
                 rgb('e5b060')])
            graph_theme = {
                'label_options': {
                    'color': rgb('444444'),
                    'bold': True
                },
                'background_color': rgb('f8f8f2'),
                'tick_color': rgb('808080'),
                'border_color': rgb('808080')
            }

            graph = Graph(xlabel='Cheese',
                          ylabel='Apples',
                          x_ticks_minor=5,
                          x_ticks_major=25,
                          y_ticks_major=1,
                          y_grid_label=True,
                          x_grid_label=True,
                          padding=5,
                          xlog=False,
                          ylog=False,
                          x_grid=True,
                          y_grid=True,
                          xmin=-50,
                          xmax=50,
                          ymin=-1,
                          ymax=1,
                          **graph_theme)

            plot = SmoothLinePlot(color=next(colors))
            plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
            graph.add_plot(plot)

            plot = MeshLinePlot(color=next(colors))
            plot.points = [(x / 10., cos(x / 50.)) for x in range(-600, 501)]
            graph.add_plot(plot)
            self.plot = plot

            plot = MeshStemPlot(color=next(colors))
            graph.add_plot(plot)
            plot.points = [(x, x / 50.) for x in range(-50, 51)]

            Clock.schedule_interval(self.update_points, 1 / 60.)

            graph2 = Graph(xlabel='Position (m)',
                           ylabel='Time (s)',
                           x_ticks_minor=0,
                           x_ticks_major=1,
                           y_ticks_major=10,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           xlog=False,
                           ylog=False,
                           xmin=0,
                           ymin=0,
                           **graph_theme)
            b.add_widget(graph)

            if np is not None:
                omega = 2 * pi / 30
                k = (2 * pi) / 2.0

                npoints = 100
                data = np.ones((npoints, npoints))

                position = [ii * 0.1 for ii in range(npoints)]
                time = [ii * 0.6 for ii in range(npoints)]

                for ii, t in enumerate(time):
                    for jj, x in enumerate(position):
                        data[ii, jj] = sin(k * x + omega * t) + sin(-k * x +
                                                                    omega * t)

                # This is required to fit the graph to the data extents
                graph2.xmax = max(position)
                graph2.ymax = max(time)

                plot = ContourPlot()
                plot.data = data
                plot.xrange = [min(position), max(position)]
                plot.yrange = [min(time), max(time)]
                plot.color = [1, 0.7, 0.2, 1]
                graph2.add_plot(plot)

                b.add_widget(graph2)

            return b
Exemple #39
0
class FormulaPlot(EventDispatcher):
    """Given a :class:`CeedFormula`, it uses that to compute the the 2D/3D
    formula output, given the range of input values.

    It supports updating the plot from a formula whose input is the output of
    another formula in a chain. In which case it starts with the input to root
    formula and evaluates all the formula in the chain until the last one. Then
    uses that to evaluate the final formula on a range of values that is then
    displayed in the graph.
    """

    graph: 'FormulaGraph' = ObjectProperty(None, rebind=True)
    """The graph in which to display the formula outputs.
    """

    plot = ObjectProperty()
    """The specific 2D/3D plot in the graph.
    """

    start = NumericProperty(0)
    """The horizontal axis start value from which to evaluate.
    """

    end = NumericProperty(100)
    """The horizontal axis end value until which to evaluate.
    """

    x2_start = NumericProperty(0)
    """The vertical axis start value from which to evaluate/display.
    """

    x2_end = NumericProperty(100)
    """The vertical axis end value until which to evaluate/display.
    """

    y_start = NumericProperty(0)
    """The depth (z) axis start value from which to display, if 3D.
    """

    y_end = NumericProperty(100)
    """The depth (z) axis end value until which to display, if 3D.
    """

    num_points = NumericProperty(100)
    """The number of horizontal/vertical points at which to evaluate the
    formula.
    """

    formula: 'CeedFormula' = ObjectProperty(None, rebind=True)
    """The :class:`CeedFormula` that takes the x (and x2 if 3D) input values and
    computes the output values.
    """

    x_variable = StringProperty('')
    """Name of the horizontal input variable.
    """

    x2_variable = StringProperty('')
    """Name of the vertical input variable, if any (3D).
    """

    x_variable_formula: 'CeedFormula' = ObjectProperty(None)
    """The formula used to generate the horizontal input variable, if it is
    part of a lens chain and the variable is the result of a previous
    formula in the chain.
    """

    x2_variable_formula: 'CeedFormula' = ObjectProperty(None)
    """The formula used to generate the vertical input variable, if it is
    part of a lens chain and the variable is the result of a previous
    formula in the chain.
    """

    y_variable = StringProperty('')
    """The name of the output (y) variable computed.
    """

    num_contours = NumericProperty(5)
    """The number of equal value contours to display for 3D plots.
    """

    track_ylim = BooleanProperty(False)
    """For 3D plots, whether to update the plot outout range as the output (y)
    range changes or if the leave it unchanged.
    """

    _last_values = {}

    _yvals = None

    _y_range = None

    _contour_plots = []

    _value_plot = None

    colors = itertools.cycle(
        [rgb('7dac9f'),
         rgb('dc7062'),
         rgb('66a8d4'),
         rgb('e5b060')])
    """Plot colors to use.
    """
    def __init__(self, **kwargs):
        super(FormulaPlot, self).__init__(**kwargs)
        self.fbind('start', self._update_from_params)
        self.fbind('end', self._update_from_params)
        self.fbind('x2_start', self._update_from_params)
        self.fbind('x2_end', self._update_from_params)
        self.fbind('num_points', self._update_from_params)
        self.fbind('x_variable', self._update_from_params)
        self.fbind('x2_variable', self._update_from_params)
        self.fbind('y_variable', self._update_from_params)
        self.fbind('formula', self._update_from_params)
        self.fbind('x_variable_formula', self._update_from_params)
        self.fbind('x2_variable_formula', self._update_from_params)

        self.fbind('y_start', self._update_y_vals)
        self.fbind('y_end', self._update_y_vals)
        self.fbind('num_contours', self._update_y_vals)

    def _update_from_params(self, *largs):
        self.refresh_plot(from_variables=False)

    def _update_y_vals(self, *largs):
        graph = self.graph
        if graph is None:
            return

        if self.x2_variable:
            if not self.plot or self._yvals is None:
                return
            self.plot.data = np.clip(self._yvals.T, self.y_start, self.y_end)
            self.compute_contours()
        else:
            graph.ymin = self.y_start
            graph.ymax = self.y_end
            graph.y_ticks_major = abs(graph.ymax - graph.ymin) / 4

    def compute_contours(self):
        """Computes the equal value contours for 3D plots.
        """
        graph = self.graph
        if graph is None or not self.x2_variable:
            return

        for plot in self._contour_plots:
            self.graph.remove_plot(plot)

        plots = self._contour_plots = []
        data = np.clip(self._yvals, self.y_start, self.y_end)
        xscale = (self.end - self.start) / self.num_points
        x2scale = (self.x2_end - self.x2_start) / self.num_points
        color = next(self.colors)

        for val in np.linspace(self.y_start, self.y_end, self.num_contours):
            contours = measure.find_contours(data, val)
            for contour in contours:
                contour[:, 0] *= xscale
                contour[:, 0] += self.start
                contour[:, 1] *= x2scale
                contour[:, 1] += self.x2_start

                plot = MeshLinePlot(color=color)
                plots.append(plot)
                graph.add_plot(plot)
                plot.points = contour

    def create_plot(self):
        """Creates and displays the plot for this formula/graph.
        """
        x2 = self.x2_variable
        plot = self.plot
        if plot is not None:
            if (x2 and isinstance(plot, ContourPlot)
                    or not x2 and isinstance(plot, LinePlot)):
                return
            self.graph.remove_plot(plot)

        for plot in self._contour_plots:
            self.graph.remove_plot(plot)
            self._contour_plots = []

        self._yvals = None
        yvar = x2 or self.y_variable
        graph_theme = {
            'label_options': {
                'color': rgb('444444'),
                'bold': True
            },
            # 'background_color': rgb('f8f8f2'),
            'tick_color':
            rgb('808080'),
            'border_color':
            rgb('808080'),
            'xlabel':
            '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(self.x_variable,
                                                       self.x_variable)),
            'ylabel':
            self.formula.variable_descriptions.get(yvar, yvar),
            'x_ticks_minor':
            5,
            # 'y_ticks_minor': 5,
            'y_grid_label':
            True,
            'x_grid_label':
            True,
            'padding':
            5,
            'x_grid':
            True,
            'y_grid':
            True,
        }

        graph = self.graph
        for k, v in graph_theme.items():
            setattr(graph, k, v)

        if x2:
            self.plot = plot = ContourPlot(color=next(self.colors))
        else:
            self.plot = plot = LinePlot(color=next(self.colors), line_width=2)
        graph.add_plot(plot)

        self._value_plot = PointPlot(color=next(self.colors), point_size=3)
        graph.add_plot(self._value_plot)

    def refresh_plot(self, from_variables=True):
        """Updates plot when any of the variables or parameters change.
        """
        if self.graph is None or not self.x_variable or not self.y_variable:
            return
        self.create_plot()

        formula = self.formula
        xvar = self.x_variable
        x2var = self.x2_variable
        # new_vals = {
        #     var: getattr(formula, var) for var in formula.x_variables
        #     if var != xvar and var != x2var}

        # if from_variables and new_vals == self._last_values:
        #     return
        # self._last_values = new_vals

        start = self.start
        end = self.end
        n = self.num_points
        plot = self.plot
        graph = self.graph
        self._yvals = None

        if x2var:
            x2_start = self.x2_start
            x2_end = self.x2_end

            xvals = np.linspace(start, end, n)
            xvals = np.repeat(np.expand_dims(xvals, 1), n, 1)

            x2vals = np.linspace(x2_start, x2_end, n)
            x2vals = np.repeat(np.expand_dims(x2vals, 1), n, 1).T

            input_variables = [(self.x_variable_formula, xvar),
                               (self.x2_variable_formula, x2var)]
            variables = {input_variables[0]: xvals, input_variables[1]: x2vals}

            yvals = formula.infer_variable_value(
                self.y_variable,
                variables,
                in_subtree={},
                input_variables=input_variables)
            if not isinstance(yvals,
                              np.ndarray) or n > 1 and yvals.shape != (n, n):
                yvals = np.zeros((n, n)) + float(yvals)
            else:
                yvals[np.logical_or(
                    np.logical_or(np.isnan(yvals), np.isinf(yvals)),
                    np.isneginf(yvals))] = -1000

            graph.xmin = start
            graph.xmax = end
            graph.ymin = x2_start
            graph.ymax = x2_end

            if self._y_range is None or self.track_ylim:
                self.y_start, self.y_end = self._y_range = \
                    float(np.min(yvals)), float(np.max(yvals))
            else:
                self._y_range = float(np.min(yvals)), float(np.max(yvals))

            graph.x_ticks_major = abs(end - start) / 10
            graph.y_ticks_major = abs(x2_end - x2_start) / 10
            graph.xlabel = '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(xvar, xvar))
            graph.ylabel = '{} -- {}'.format(
                self.x2_variable_formula.widget.name,
                self.formula.variable_descriptions.get(x2var, x2var))

            plot.xrange = (start, end)
            plot.yrange = (x2_start, x2_end)
            plot.data = np.clip(yvals.T, self.y_start, self.y_end)
            self._yvals = yvals

            self.compute_contours()
            self._value_plot.points = [(getattr(self.x_variable_formula, xvar),
                                        getattr(self.x2_variable_formula,
                                                x2var))]
        else:
            xvals = np.linspace(start, end, n)

            input_variables = [(self.x_variable_formula, xvar)]
            variables = {input_variables[0]: xvals}
            yvals = formula.infer_variable_value(
                self.y_variable,
                variables,
                in_subtree={},
                input_variables=input_variables)

            if not isinstance(
                    yvals,
                (np.ndarray, np.generic)) or n > 1 and len(yvals) == 1:
                yvals = np.zeros((n, )) + float(yvals)
            else:
                yvals[np.logical_or(
                    np.logical_or(np.isnan(yvals), np.isinf(yvals)),
                    np.isneginf(yvals))] = -1000

            ymin, ymax = np.min(yvals), np.max(yvals)
            if math.isclose(ymin, ymax):
                ydiff = abs(ymin) * 0.2
            else:
                ydiff = (ymax - ymin) * .02

            graph.xmin = start
            graph.xmax = end
            if self._y_range is None or self.track_ylim:
                self.y_start, self.y_end = self._y_range = \
                    float(ymin - ydiff), float(ymax + ydiff)
            else:
                self._y_range = float(ymin - ydiff), float(ymax + ydiff)
            graph.ymin = self.y_start
            graph.ymax = self.y_end

            graph.x_ticks_major = abs(end - start) / 10
            graph.y_ticks_major = abs(graph.ymax - graph.ymin) / 4
            graph.xlabel = '{} -- {}'.format(
                self.x_variable_formula.widget.name,
                self.formula.variable_descriptions.get(xvar, xvar))
            graph.ylabel = self.formula.variable_descriptions.get(
                self.y_variable, self.y_variable)

            plot.points = list(zip(xvals, yvals))
            self._value_plot.points = [(getattr(self.x_variable_formula, xvar),
                                        getattr(formula, self.y_variable))]

    def reset_y_axis(self):
        """Resets the y (output)-axis to the previous value.
        """
        if not self.graph or not self.plot or self._y_range is None:
            return

        self.y_start, self.y_end = self._y_range
Exemple #40
0
    def make_layout(self):
        layout = BoxLayout(orientation="vertical")

        settingslayout = BoxLayout(orientation="horizontal")
        left_settings = BoxLayout(orientation="horizontal")
        settingslayout.add_widget(left_settings)

        on_off_layout = BoxLayout(orientation="vertical")
        self.on_off_layout = on_off_layout

        button_heating = Button(background_normal="pic/flame_off.png",
                                background_down="pic/flame_pressed.png",
                                allow_stretch=False,
                                size_hint=(0.7, 1),
                                border=[0, 0, 0, 0])
        button_heating.bind(on_press=self.on_button_heating)
        self.button_heating = button_heating

        button_pump = Button(background_normal="pic/pump_off.png",
                             background_down="pic/pump_pressed.png",
                             allow_stretch=False,
                             size_hint=(0.7, 1),
                             border=[0, 0, 0, 0])
        button_pump.bind(on_press=self.on_button_pump)
        self.button_pump = button_pump

        temperatur_panel = BoxLayout(orientation="vertical")

        oil_temp_label = Label(text="0 Grad", color=[0, 0, 0, 1], font_size=30)
        self.oil_temp_label = oil_temp_label
        temperatur_panel.add_widget(oil_temp_label)

        water_temp_label = Label(text="0 Grad",
                                 color=[0, 0, 0, 1],
                                 font_size=30)
        self.water_temp_label = water_temp_label
        temperatur_panel.add_widget(water_temp_label)

        time_label = Label(text="0 min", color=[0, 0, 0, 1], font_size=30)
        self.time_label = time_label
        temperatur_panel.add_widget(time_label)

        heating_image = Image(source='pic/heating_off.png')
        self.heating_image = heating_image
        temperatur_panel.add_widget(heating_image)

        names_panel = BoxLayout(orientation="vertical")
        name_oil = Label(text="Öl:", color=[0, 0, 0, 1], font_size=30)
        names_panel.add_widget(name_oil)
        name_water = Label(text="Wasser:", color=[0, 0, 0, 1], font_size=30)
        names_panel.add_widget(name_water)
        name_time = Label(text="Zeit:", color=[0, 0, 0, 1], font_size=30)
        names_panel.add_widget(name_time)
        name_heating = Label(text="Heizen:", color=[0, 0, 0, 1], font_size=30)
        names_panel.add_widget(name_heating)

        set_value_panel = BoxLayout(orientation="vertical")
        set_value_oil_panel = BoxLayout(orientation="horizontal")
        set_value_water_panel = BoxLayout(orientation="horizontal")
        set_delta_heating_panel = BoxLayout(orientation="horizontal")
        set_delta_cooling_panel = BoxLayout(orientation="horizontal")
        set_value_panel.add_widget(set_value_oil_panel)
        set_value_panel.add_widget(set_value_water_panel)
        set_value_panel.add_widget(set_delta_heating_panel)
        set_value_panel.add_widget(set_delta_cooling_panel)

        set_oil_temp_slider = Slider(min=0, max=150, value=50)
        self.set_oil_temp_slider = set_oil_temp_slider
        set_oil_temp_slider.bind(value=self.on_set_oil_temp_slider)
        set_value_oil_panel.add_widget(set_oil_temp_slider)
        set_oil_temp_label = Label(text="50 °C",
                                   color=[0, 0, 0, 1],
                                   font_size=30,
                                   size_hint=(None, 1))
        self.set_oil_temp_label = set_oil_temp_label
        set_value_oil_panel.add_widget(set_oil_temp_label)

        set_water_temp_slider = Slider(min=0, max=50, value=10)
        self.set_water_temp_slider = set_water_temp_slider
        set_water_temp_slider.bind(value=self.on_set_water_temp_slider)
        set_value_water_panel.add_widget(set_water_temp_slider)
        set_water_temp_label = Label(text="10 °C",
                                     color=[0, 0, 0, 1],
                                     font_size=30,
                                     size_hint=(None, 1))
        self.set_water_temp_label = set_water_temp_label
        set_value_water_panel.add_widget(set_water_temp_label)

        name_delta_heating_label = Label(text=u"\u0394" + "Th",
                                         color=[0, 0, 0, 1],
                                         font_size=30,
                                         size_hint=(None, 1))
        set_delta_heating_panel.add_widget(name_delta_heating_label)
        set_delta_heating_slider = Slider(min=0, max=10, value=5)
        self.set_delta_heating_slider = set_delta_heating_slider
        set_delta_heating_slider.bind(value=self.on_set_delta_heating_slider)
        set_delta_heating_panel.add_widget(set_delta_heating_slider)
        set_delta_heating_label = Label(text="5 °C",
                                        color=[0, 0, 0, 1],
                                        font_size=30,
                                        size_hint=(None, 1))
        self.set_delta_heating_label = set_delta_heating_label
        set_delta_heating_panel.add_widget(set_delta_heating_label)

        name_delta_cooling_label = Label(text=u"\u0394" + "Tk",
                                         color=[0, 0, 0, 1],
                                         font_size=30,
                                         size_hint=(None, 1))
        set_delta_cooling_panel.add_widget(name_delta_cooling_label)
        set_delta_cooling_slider = Slider(min=0, max=10, value=5)
        self.set_delta_cooling_slider = set_delta_cooling_slider
        set_delta_cooling_slider.bind(value=self.on_set_delta_cooling_slider)
        set_delta_cooling_panel.add_widget(set_delta_cooling_slider)
        set_delta_cooling_label = Label(text="5 °C",
                                        color=[0, 0, 0, 1],
                                        font_size=30,
                                        size_hint=(None, 1))
        self.set_delta_cooling_label = set_delta_cooling_label
        set_delta_cooling_panel.add_widget(set_delta_cooling_label)

        left_settings.add_widget(on_off_layout)
        left_settings.add_widget(names_panel)
        left_settings.add_widget(temperatur_panel)
        settingslayout.add_widget(set_value_panel)
        on_off_layout.add_widget(button_heating)
        on_off_layout.add_widget(button_pump)
        layout.add_widget(settingslayout)

        with layout.canvas.before:
            Color(1, 1, 1, 1)
            layout.rect = Rectangle(size=layout.size, pos=layout.pos)

        layout.bind(pos=self.update_rect, size=self.update_rect)

        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True
            },
            'background_color': rgb('ffffff'),  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')
        }
        graph_oil = Graph(xlabel="Zeit [s]",
                          ylabel="Öltemperatur [°C]",
                          x_ticks_major=1,
                          y_ticks_major=1,
                          y_grid_label=True,
                          x_grid_label=True,
                          padding=5,
                          xlog=False,
                          ylog=False,
                          x_grid=True,
                          y_grid=True,
                          xmin=0,
                          xmax=10,
                          **graph_theme)
        self.graph_oil = graph_oil

        graph_water = Graph(xlabel="Zeit [s]",
                            ylabel="Wassertemperatur [°C]",
                            x_ticks_major=1,
                            y_ticks_major=10,
                            y_grid_label=True,
                            x_grid_label=True,
                            padding=5,
                            xlog=False,
                            ylog=False,
                            x_grid=True,
                            y_grid=True,
                            xmin=0,
                            xmax=10,
                            **graph_theme)
        self.graph_water = graph_water

        plot_oil = SmoothLinePlot(color=rgb('ff0000'))
        self.plot_oil = plot_oil

        plot_oil_set = SmoothLinePlot(color=rgb('00ff00'))
        self.plot_oil_set = plot_oil_set

        plot_water = SmoothLinePlot(color=rgb('0000ff'))
        self.plot_water = plot_water
        plot_water.points = [(x, x * x) for x in range(0, 11)]
        graph_oil.add_plot(plot_oil)
        graph_oil.add_plot(plot_oil_set)
        graph_water.add_plot(plot_water)
        layout.add_widget(graph_oil)
        layout.add_widget(graph_water)

        return layout
Exemple #41
0
    def make_graph_display(self):
        b = BoxLayout(orientation='vertical')
        colors = itertools.cycle(
            [rgb('7dac9f'),
             rgb('dc7062'),
             rgb('66a8d4'),
             rgb('e5b060')])
        graph_theme = {
            'label_options': {
                'color': rgb('B0B0B0'),  # color of tick labels and titles
                'bold': False
            },
            'background_color':
            rgb('000000'),  # rgb('f8f8f2'),  # back ground color of canvas
            'tick_color': rgb('B0B0B0'),  # ticks and grid
            'border_color': rgb('808080')
        }  # border drawn around each graph

        graph = Graph(xlabel='Cheese',
                      ylabel='Apples',
                      x_ticks_minor=25,
                      x_ticks_major=100,
                      y_ticks_major=10,
                      y_grid_label=True,
                      x_grid_label=True,
                      padding=5,
                      xlog=False,
                      ylog=False,
                      x_grid=True,
                      y_grid=True,
                      xmin=-50,
                      xmax=50,
                      ymin=-1,
                      ymax=1,
                      **graph_theme)

        self.graph = graph

        # plot = SmoothLinePlot(color=next(colors))
        # plot.points = [(x / 10., sin(x / 50.)) for x in range(-500, 501)]
        # for efficiency, the x range matches xmin, xmax
        #graph.add_plot(plot)

        plot = MeshLinePlot(color=next(colors))
        plot.points = [(x / 10., cos(x / 50.)) for x in range(-500, 501)]
        graph.add_plot(plot)
        self.plot = plot  # this is the moving graph, so keep a reference

        # plot = MeshStemPlot(color=next(colors))
        # graph.add_plot(plot)
        # plot.points = [(x, x / 50.) for x in range(-50, 51)]

        # plot = BarPlot(color=next(colors), bar_spacing=.72)
        # graph.add_plot(plot)
        # plot.bind_to_graph(graph)
        # plot.points = [(x, .1 + randrange(10) / 10.) for x in range(-50, 1)]

        # Clock.schedule_interval(self.update_points, 1 / 60.)
        b.add_widget(graph)
        """
        graph2 = Graph(
            xlabel='Position (m)',
            ylabel='Time (s)',
            x_ticks_minor=0,
            x_ticks_major=1,
            y_ticks_major=10,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            xlog=False,
            ylog=False,
            xmin=0,
            ymin=0,
            **graph_theme)

        if np is not None:
            (xbounds, ybounds, data) = self.make_contour_data()
            # This is required to fit the graph to the data extents
            graph2.xmin, graph2.xmax = xbounds
            graph2.ymin, graph2.ymax = ybounds

            plot = ContourPlot()
            plot.data = data
            plot.xrange = xbounds
            plot.yrange = ybounds
            plot.color = [1, 0.7, 0.2, 1]
            graph2.add_plot(plot)

            b.add_widget(graph2)
            self.contourplot = plot

            Clock.schedule_interval(self.update_contour, 1 / 60.)
        """

        return b
    def __init__(self, **kwargs):
        super(Scatter2DGraph, self).__init__(**kwargs)

        self.orientation = "vertical"

        self._colors = itertools.cycle([rgb('8e44ad'), rgb('b7ff00'), rgb('DB0A5B'),
                                        rgb('C8F7C5'), rgb(
                                            '34495e'), rgb('f1c40f'),
                                        rgb('6C7A89'), rgb(
                                            'BFBFBF'), rgb('00CCFF'),
                                        rgb('e67e22')
                                        ])

        self._graph_theme = {
            'label_options': {
                'color': rgb('99ccff'),  # color of tick labels and titles
                'bold': True},
            # 3B3C3D back ground color of canvas 738ffe
            'background_color': rgb('3B3C3D'),
            'tick_color': rgb('5588ff'),  # ticks and grid
            'border_color': rgb('5588ff')}  # border drawn around each graph

        self._agraph = None