def graphpoints(self, *args): hotendactual_plot = SmoothLinePlot(color=[1, 0, 0, 1]) hotendtarget_plot = MeshLinePlot(color=[1, 0, 0, .75]) bedactual_plot = SmoothLinePlot(color=[0, 0, 1, 1]) bedtarget_plot = MeshLinePlot(color=[0, 0, 1, .75]) # Build list of plot points tuples from temp and time lists # FIXME - Need to reduce the number of points on the graph. 360 is overkill hotendactual_points_list = [] hotendtarget_points_list = [] bedactual_points_list = [] bedtarget_points_list = [] for i in range(360): hotendactual_points_list.append( (graphtime_list[i] / 1000.0 * -1, hotendactual_list[i])) hotendtarget_points_list.append( (graphtime_list[i] / 1000.0 * -1, hotendtarget_list[i])) bedactual_points_list.append( (graphtime_list[i] / 1000.0 * -1, bedactual_list[i])) bedtarget_points_list.append( (graphtime_list[i] / 1000.0 * -1, bedtarget_list[i])) # Remove all old plots from the graph before drawing new ones for plot in self.my_graph.plots: self.my_graph.remove_plot(plot) # Draw the new graphs hotendactual_plot.points = hotendactual_points_list self.my_graph.add_plot(hotendactual_plot) hotendtarget_plot.points = hotendtarget_points_list self.my_graph.add_plot(hotendtarget_plot) bedactual_plot.points = bedactual_points_list self.my_graph.add_plot(bedactual_plot) bedtarget_plot.points = bedtarget_points_list self.my_graph.add_plot(bedtarget_plot)
def __init__(self, **kwargs): super(CustomGraph, self).__init__(**kwargs) 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 = -5 self.ymax = 5 #graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, # 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=-5, ymax=5) plot1 = MeshLinePlot(color=[1, 0, 0, 1]) plot1.points = [(x, sin(x)) for x in range(0, 101)] plot2 = MeshLinePlot(color=[0, 1, 0, 1]) plot2.points = [(x, cos(x)) for x in range(0, 101)] plot3 = MeshLinePlot(color=[0, 0, 1, 1]) plot3.points = [(x, tan(x)) for x in range(0, 101)] self.add_plot(plot1) self.add_plot(plot2) self.add_plot(plot3)
def graphpoints(self, *args): hotendactual_plot = SmoothLinePlot(color=[1, 0, 0, 1]) hotendtarget_plot = MeshLinePlot(color=[1, 0, 0, .75]) bedactual_plot = SmoothLinePlot(color=[0, 0, 1, 1]) bedtarget_plot = MeshLinePlot(color=[0, 0, 1, .75]) #Build list of plot points tuples from temp and time lists ##FIXME - Need to reduce the number of points on the graph. 360 is overkill hotendactual_points_list = [] hotendtarget_points_list = [] bedactual_points_list = [] bedtarget_points_list = [] for i in range(360): hotendactual_points_list.append( (graphtime_list[i]/1000.0*-1, hotendactual_list[i]) ) hotendtarget_points_list.append( (graphtime_list[i]/1000.0*-1, hotendtarget_list[i]) ) bedactual_points_list.append( (graphtime_list[i]/1000.0*-1, bedactual_list[i]) ) bedtarget_points_list.append( (graphtime_list[i]/1000.0*-1, bedtarget_list[i]) ) #Remove all old plots from the graph before drawing new ones for plot in self.my_graph.plots: self.my_graph.remove_plot(plot) #Draw the new graphs hotendactual_plot.points = hotendactual_points_list self.my_graph.add_plot(hotendactual_plot) hotendtarget_plot.points = hotendtarget_points_list self.my_graph.add_plot(hotendtarget_plot) bedactual_plot.points = bedactual_points_list self.my_graph.add_plot(bedactual_plot) bedtarget_plot.points = bedtarget_points_list self.my_graph.add_plot(bedtarget_plot)
def graphpoints(self, *args): global g_hotend_actual global g_hotend_target global g_bed_actual global g_bed_target hotendactual_plot = SmoothLinePlot(color=[1, 0, 0, 1]) hotendtarget_plot = MeshLinePlot(color=[1, 0, 0, .75]) bedactual_plot = SmoothLinePlot(color=[0, 0, 1, 1]) bedtarget_plot = MeshLinePlot(color=[0, 0, 1, .75]) # Update temperature graph arrays with new data hotendactual_list.popleft() hotendactual_list.append(g_hotend_actual) hotendtarget_list.popleft() hotendtarget_list.append(g_hotend_target) bedactual_list.popleft() bedactual_list.append(g_bed_actual) bedtarget_list.popleft() bedtarget_list.append(g_bed_target) # Build list of plot points tuples from temp and time lists hotendactual_points_list = [] hotendtarget_points_list = [] bedactual_points_list = [] bedtarget_points_list = [] for i in range(temperature_list_size): hotendactual_points_list.append( (graphtime_list[i] / 1000.0 * -1, int(hotendactual_list[i]))) hotendtarget_points_list.append( (graphtime_list[i] / 1000.0 * -1, int(hotendtarget_list[i]))) bedactual_points_list.append( (graphtime_list[i] / 1000.0 * -1, int(bedactual_list[i]))) bedtarget_points_list.append( (graphtime_list[i] / 1000.0 * -1, int(bedtarget_list[i]))) # Remove all old plots from the graph before drawing new ones while (len(self.my_graph.plots) != 0): # TODO - add a counter so we can abort after a certain number of tries. self.my_graph.remove_plot(self.my_graph.plots[0]) # Draw the new graphs hotendactual_plot.points = hotendactual_points_list self.my_graph.add_plot(hotendactual_plot) hotendtarget_plot.points = hotendtarget_points_list self.my_graph.add_plot(hotendtarget_plot) bedactual_plot.points = bedactual_points_list self.my_graph.add_plot(bedactual_plot) bedtarget_plot.points = bedtarget_points_list self.my_graph.add_plot(bedtarget_plot)
def build(self): experiment = Experiment() plot = MeshLinePlot(color=[0,.75,.75,1]) plot.points = [] experiment.ids.graph.add_plot(plot) Clock.schedule_interval(partial(experiment.task, plot), 0.0) return experiment
def graph_add(self): #self.remove_widget(graph1) global plot k = np.random.normal() plot = MeshLinePlot(color=[0, 0, 0.75, 1]) plot.points = [(x, sin(x / k)) for x in range(0, 101)] graph1.add_plot(plot)
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 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
def Create_Graph(self): for plot in self.graph.plots: self.graph.remove_plot(plot) n = int(self.p.text) if ((n % 2) == 0): list_b = [] i = -1 while i < 1: list_b.append(i) i = i + 0.1 data = [(x, (abs(1 - (x**n)))**(1 / n)) for x in list_b] data += [(x, ((abs(1 - (x**n)))**(1 / n) * -1)) for x in list_b] else: list_a = [] i = -4 while i < 1: list_a.append(i) i = i + 0.1 list_b = [] i = 1 while i < 6: list_b.append(i) i = i + 0.1 data = [(x, (abs(1 - (x**n)))**(1 / n)) for x in list_a] data += [(x, ((abs(1 - (x**n)))**(1 / n)) * -1) for x in list_b] plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = data self.graph.add_plot(plot)
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
def load_graf(self,graf): #loads graph, updates global variable metrics with newest data0 global metrics, scaledmetrics graf.clear_widgets() try: RRData = ReadData() except: pass n=30 # n is currently used for RRMetrics and the number of points graphed. Split this try: pos = metrics[0][2][0] #Integer value of how many data points there have been except: pos = 0 graph = (Graph(xlabel = 'Data Point', ylabel = '% of Maximum', x_ticks_minor =1, x_ticks_major=2, y_ticks_minor=5,y_ticks_major=25,y_grid_label=True,x_grid_label=True, padding=5,x_grid=True,y_grid=True,xmin=max(0,pos-n+1),xmax=max(1,pos+1),ymin=0,ymax=100)) #Mod ymax/min based on bars xD for DataArray in scaledmetrics: metric = DataArray[0] #Metric Name as string colour = DataArray[1] #Metric colour plot = MeshLinePlot(color = colour) plot.points = tuple(DataArray[2:32]) #Replace 32 with some n variable plot.size = (1,1,100,100) graph.add_plot(plot) graf.add_widget(graph)
def load1_Score(self, path, filename): with open(filename[0], 'r') as stream: global micefeat global X array1 = pd.read_csv(stream) array = array1.values X = array[:, 2:56] plot = MeshLinePlot(color=[1, 0, 0, 1]) X_scaled = preprocessing.scale(X[:, 0]) plot.points = [(y, X_scaled[y]) for y in range(0, 500)] self.graph_test.add_plot(plot) global score_feat score_fe = array1.loc[:, 'time_stamps'] score_feat = pd.DataFrame(score_fe) score_feat.insert(1, 'EEG_spindelhan', array1.loc[:, 'EEG_spindelhan']) score_feat.insert(2, 'EMG_amplitude', array1.loc[:, 'EMG_amplitude']) score_feat.insert(3, 'EEG_delta', array1.loc[:, 'EEG_delta']) score_feat.insert(4, 'EMG_spectral_entropy', array1.loc[:, 'EMG_spectral_entropy']) score_feat.insert(5, 'EEG_theta1', array1.loc[:, 'EEG_theta1']) score_feat.insert(6, 'EEG_zerocross', array1.loc[:, 'EEG_zerocross']) self.dismiss_popup()
def update_graph(self): SS = SecondScreen() x = SS.data[0] y = SS.data[1] plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = [(x[i], y[i]) for i in range(len(x))] self.graph_test.add_plot(plot)
def build(self): self.title = "HP4156C Parameter Analyser" ## Main screen has a title and two accordions root = BoxLayout(orientation='vertical') ## Add a title header to the window graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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) plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = [(x, sin(x / 10.)) for x in range(0, 101)] graph.add_plot(plot) root.add_widget(graph) return root
def build(self): print 'create graph' #self.canvas.add(Color(1., 1., 0)) graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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) plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = [(x, sin(x / 10.)) for x in range(0, 101)] graph.add_plot(plot) return graph
class ProgressScreenRow(RecycleDataViewBehavior, BoxLayout): index = None selected = BooleanProperty(False) selectable = BooleanProperty(True) rv_data = ObjectProperty(None) rv = ObjectProperty(None) def __init__(self, **kwargs): super(ProgressScreenRow, self).__init__(**kwargs) self.plot = MeshLinePlot(color=[1, 0, 0, 1]) def refresh_view_attrs(self, rv, index, data): ''' Catch and handle the view changes ''' self.index = index #self.ids.graph.add_plot(self.plot) #self.plot.points(self.sensor_date, self.data_points) return super(ProgressScreenRow, self).refresh_view_attrs(rv, index, data) def on_touch_down(self, touch): ''' Add selection on touch down ''' if super(ProgressScreenRow, self).on_touch_down(touch): return True if self.collide_point(*touch.pos) and self.selectable: return self.parent.select_with_touch(self.index, touch) def apply_selection(self, rv, index, is_selected): self.rv = rv self.rv_data = rv.data self.index = index self.selected = is_selected print(self.index) def remove(self): print('REMOVE ENTRY') if self.rv: self.rv.data.pop(self.index) def add_plot(self): self.ids.graph.add_plot(self.plot) self.plot.points(self.sensor_date, self.data_points)
def build(self): self.availablePorts = listSerialPorts() if len(self.availablePorts) == 0: self.availablePorts.append("----") tabbedPannel = TabbedPanel(do_default_tab=False) # Connection Tab self.connectionTab = TabbedPanelItem(text="Connection") self.layout1 = BoxLayout(orientation='vertical', spacing=10, padding=(200, 200)) self.connectionTab.add_widget(self.layout1) self.lblSerialSettings = Label(text="Connection settings") self.layout1.add_widget(self.lblSerialSettings) self.dlBaudrate = Spinner(values = ["57600", "115200", "230400", "460800", "921600"], text = "115200") self.layout1.add_widget(self.dlBaudrate) self.dlPort = Spinner(values = self.availablePorts, text = self.availablePorts[0]) self.layout1.add_widget(self.dlPort) self.btnConnect = Switch() self.btnConnect.bind(active = self.connect) self.layout1.add_widget(self.btnConnect) # Graph tab self.graphTab = TabbedPanelItem(text = "Graph") # self.layout2 = BoxLayout(orientation='vertical', spacing=10, padding=(200, 200)) # self.graphTab.add_widget(self.layout2) graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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) plot = MeshLinePlot(color=[1, 1, 0, 1]) plot.points = [(x, sin(x / 10.)) for x in range(0, 101)] graph.add_plot(plot) self.graphTab.add_widget(graph) tabbedPannel.add_widget(self.connectionTab) tabbedPannel.add_widget(self.graphTab) return tabbedPannel
def build(self): print 'create graph' graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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=10, ymin=-12, ymax=12) plot = MeshLinePlot(color=[1, 0, 0, 1]) with open("adclog.txt") as fh: coords = [] for line in fh: line = line.strip('()\n') # Get rid of the newline and parentheses line = line.split(', ') # Split into two parts c = tuple(float(x) for x in line) # Make the tuple coords.append(c) plot.points = coords graph.add_plot(plot) return graph
def mostrar_histograma(self): """ Mostra o histograma da imagem. """ histograma = self.imagem_core.get_histograma() graph = Graph(xlabel='Tom de Cinza', ylabel='Quantidade de tons', padding=5, xmin=0, xmax=max(histograma.keys()), ymin=0, ymax=max(histograma.values())) plot = MeshLinePlot() plot.points = histograma.items() graph.add_plot(plot) self.widgets_dinamicos.append(graph) self.add_widget(graph)
def zaladujModel(self, sciezka): import random self.data.loadFile(sciezka, app, wantSorted=True, index=0) for property in self.data.temp: r = lambda: random.randint(0, 255) / 255.0 plot = MeshLinePlot(color=[r(), r(), r(), 1]) points = [] i = 0 for object in self.data.data: try: value = float(object[property]) points.append((i, value)) except (ValueError, KeyError): pass i += 1 plot.points = points app.graphScreen.getGraph().add_plot(plot)
def __init__(self, **kwargs): super(BElGenLiveGraph, self).__init__(**kwargs) graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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=10, ymin=-12, ymax=12) plot = MeshLinePlot(color=[1, 0, 0, 1]) with open("adclog.txt") as fh: coords = [] for line in fh: line = line.strip('()\n') # Get rid of the newline and parentheses line = line.split(', ') # Split into two parts c = tuple(float(x) for x in line) # Make the tuple coords.append(c) plot.points = coords graph.add_plot(plot) self.add_widget(graph)
def load_Feat(self, path, filename): with open(os.path.join(path, filename[0]), 'r') as stream: global data_frame print(filename[0]) print(stream) eeg1, eeg2, emg, time_stamps = readEDFfile(filename[0], EMGC, EEGC, epoch) print("EDF read") print(eeg1) print(emg) data_frame = CreateFeaturesDataFrame(eeg1, emg, epoch, fs) data_frame['time_stamps'] = time_stamps plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = [(x, eeg1[x]) for x in range(0, 1500)] self.graph_test.add_plot(plot) self.dismiss_popup()
def zaladujModel(self,sciezka): import random self.data.loadFile(sciezka, app, wantSorted=True, index=0) for property in self.data.temp: r = lambda: random.randint(0,255)/255.0 plot = MeshLinePlot(color=[r(), r(), r(), 1]) points = [] i = 0 for object in self.data.data: try: value = float(object[property]) points.append((i, value)) except (ValueError, KeyError): pass i+=1 plot.points = points app.graphScreen.getGraph().add_plot(plot)
def plotGraph(self, amplit): numAmp = float(amplit) self.my_output.text = "graph" for plot in self.my_graph.plots: self.my_graph.remove_plot(plot) plot = MeshLinePlot(mode="line_strip", color=[1, 0, 0, 1]) plot.points = [(x, 10 * np.sin(0.5 * x / numAmp)) for x in xrange(-0, 100)] self.my_graph.add_plot(plot) self.my_graph.x_ticks_major = 25 self.my_graph.y_ticks_major = 25 self.my_graph.xmin = -0 self.my_graph.xmax = 100 self.my_graph.ymin = -25 self.my_graph.ymax = 25 self.my_graph.xlabel = "X axis" self.my_graph.ylabel = "Y axis"
def plotGraph(self, amplit): numAmp = float(amplit) self.my_output.text = "graph" for plot in self.my_graph.plots: self.my_graph.remove_plot(plot) plot = MeshLinePlot(mode='line_strip', color=[1, 0, 0, 1]) plot.points = [(x, 10 * np.sin(0.5 * x / numAmp)) for x in xrange(-0, 100)] self.my_graph.add_plot(plot) self.my_graph.x_ticks_major = 25 self.my_graph.y_ticks_major = 25 self.my_graph.xmin = -0 self.my_graph.xmax = 100 self.my_graph.ymin = -25 self.my_graph.ymax = 25 self.my_graph.xlabel = 'X axis' self.my_graph.ylabel = 'Y axis'
def __init__(self, **kwargs): super(RootWidget, self).__init__(**kwargs) graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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.background_color = 0, 0, 1, 1 # blue color plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = [(x, sin(x / 10.)) for x in range(0, 101)] graph.add_plot(plot) self.add_widget(graph)
ylabel='Y', title='Output', xmin=0, xmax=val, ymin=-0.5, ymax=1.5) plotOut = MeshLinePlot(color=[1, 0, 0, 1]) graphOutput.add_plot(plotOut) ber = Label() x = np.random.randint(0, 2, size=val).reshape(val, 1) bip = lambda i: (i * 2) - 1 y = bip(x) x_diplay = np.matmul(y, np.ones(shape=(1, 20))).flatten() plotIn.points = [(i / 20, x_diplay[i]) for i in range(len(x_diplay))] I = np.matmul(np.array(list(y)[0::2]).reshape(val // 2, 1), s.transpose()).flatten() Q = np.matmul(np.array(list(y)[1::2]).reshape(val // 2, 1), c.transpose()).flatten() QPSK = I + Q plotQPSK.points = [(i, QPSK[i]) for i in range(len(QPSK))] def refresh(sc): # Rayleigh channel r = np.random.rayleigh(sc, size=len(QPSK)) tx = QPSK + r # Demodulation
def __init__(self, **kwargs): super(MainLayout, self).__init__(**kwargs) def redraw(self, args): self.bg_rect.size = self.size self.bg_rect.pos = self.pos with self.canvas: self.bg_rect = Rectangle(source="steel.jpg", pos=self.pos, size=self.size) self.bind(pos=redraw, size=redraw) root = BoxLayout(orientation='vertical', padding=[15], spacing=15) # Add loading file with data gl = GridLayout(cols=2, size_hint=(1, 0.95), size_hint_min=(100, 100), spacing=10) # Results section resl = BoxLayout(size_hint=(0.6, 0.98), size_hint_min=(100, 100), orientation='vertical', spacing=15) # Graph graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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) plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = [(x, x) for x in range(0, 101)] graph.add_plot(plot) resl.add_widget(graph) # Options section bl = BoxLayout(size_hint=(0.4, 0.98), size_hint_min=(100, 100), orientation='vertical', spacing=15) bl.add_widget( Label(text='Wybierz plik danych', size_hint=(1, 0.05), size_hint_min=(200, 20))) files = FileChooserListView(size_hint=(1, 0.95), path=os.environ['HOMEDRIVE'] \ + os.environ['HOMEPATH']) bl.add_widget(files) bl.add_widget( Label(text='Wybierz metodę interpolacji', size_hint=(1, 0.05), size_hint_min=(200, 30))) # Choosing interpolation method dd = DropDown() for interpolation in ['liniowa', 'wielomianowa']: btn = Button(text=interpolation, size_hint_y=None, height=30) btn.bind(on_release=lambda btn: dd.select(btn.text)) dd.add_widget(btn) dd_interpol_btn = Button(text='liniowa', size_hint=(1, 0.05), size_hint_min=(80, 30)) dd_interpol_btn.bind(on_release=dd.open) dd.bind( on_select=lambda instance, x: setattr(dd_interpol_btn, 'text', x)) bl.add_widget(dd_interpol_btn) # Add widgets to root layout root.add_widget( Label(text='Entalpy Calculator', size_hint=(1, 0.05), size_hint_min_y=20)) gl.add_widget( Label(text='Wyniki', size_hint=(0.6, 0.02), size_hint_min_y=20)) gl.add_widget( Label(text='Opcje', size_hint=(0.4, 0.02), size_hint_min_y=20)) gl.add_widget(resl) gl.add_widget(bl) root.add_widget(gl) calculate_btn = Button(text='Oblicz', size_hint=(1, 0.05), size_hint_min_y=30) calc_callback = partial(calculate, file_chooser=files, ip_btn=dd_interpol_btn) calculate_btn.bind(on_release=calc_callback) root.add_widget(calculate_btn) self.add_widget(root)
def addData(self): p = MeshLinePlot(color=[1,0,0,1]) p.points = [(x, 0.5) for x in range(-10,10)] self.ids['my_graph'].add_plot(p)
def __init__(self, data_file, measure_collections_f, additional_interval, restart=True, **kwargs): super(VisualizationApp, self).__init__(**kwargs) self.restart = restart self.data_file = data_file self.additional_interval = additional_interval self.camera_folder = data_file + '_images_Camera\\' self.camera_files = sorted([ f for f in os.listdir(self.camera_folder) if os.path.isfile(os.path.join(self.camera_folder, f)) and f.endswith('.jpg') ]) self.ground_truth_file = [ os.path.join(self.camera_folder, f) for f in os.listdir(self.camera_folder) if os.path.isfile(os.path.join(self.camera_folder, f)) and f.startswith('00gt') ][0] self.image = Image(source=os.path.join(self.camera_folder, self.camera_files[0]), size=(352, 288), pos=(0, 0)) #with self.image.canvas as canvas: # Color(1., 0, 0) # Rectangle(size=(1, 10000)) self.graph = Graph( xlabel='Time [s]', ylabel='Distance [m]', #x_ticks_minor=0.5, x_ticks_major=2, y_ticks_major=1, y_grid_label=True, x_grid_label=True, padding=10, x_grid=True, y_grid=True, xmin=0, xmax=0, ymin=-1, ymax=11) last_mc = None self.first_timestamp = measure_collections_f[0].first_measure( ).timestamp for mc in measure_collections_f: color = [1, 1, 0, 1] if mc.prediction == 'FREE_SPACE': color = [1, 0, 1, 1] elif mc.prediction == 'PARKING_CAR': color = [0, 1, 1, 1] elif mc.prediction == 'OVERTAKING_SITUATION': color = [0, 0, 1, 1] plot = MeshLinePlot(color=color) plot.points = [(m.timestamp - self.first_timestamp, m.distance) for m in mc.measures] self.graph.add_plot(plot) color_actual = [1, 1, 0, 1] if mc.get_probable_ground_truth() == GroundTruthClass.FREE_SPACE: color_actual = [1, 0, 1, 1] elif GroundTruthClass.is_parking_car( mc.get_probable_ground_truth()): color_actual = [0, 1, 1, 1] elif GroundTruthClass.is_overtaking_situation( mc.get_probable_ground_truth()): color_actual = [0, 0, 1, 1] plot_actual = MeshLinePlot(color=color_actual) plot_actual.points = [(m.timestamp - self.first_timestamp, m.distance - 0.1) for m in mc.measures] self.graph.add_plot(plot_actual) if last_mc is not None: plot_next = MeshLinePlot(color=[1, 1, 1, 1]) plot_next.points = [ (last_mc.last_measure().timestamp - self.first_timestamp, last_mc.last_measure().distance), (mc.first_measure().timestamp - self.first_timestamp, mc.first_measure().distance) ] self.graph.add_plot(plot_next) last_mc = mc # plot = MeshLinePlot(color=[1, 1, 1, 1]) # plot.points = [(m.timestamp - self.first_timestamp, m.distance) for m in self.measurements] # self.graph.add_plot(plot) self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.running = True self.cur_index = -1 self.show_next_image(0)
def on_open(self): plot = MeshLinePlot(color=[0,1,1,1]) plot.points = zip(np.arange(self.spectrum.size), self.spectrum) self.ids.graph.add_plot(plot)
def graph(self): soln_graph = screen_manager.get_screen('solution').layout fx = Fx(shunt(self.eq)).eval colors = itertools.cycle([ rgb('dc7062'), rgb('fff400'), rgb('7dac9f'), rgb('66a8d4'), rgb('e5b060') ]) fxplot = SmoothLinePlot(color=next(colors)) for i in range(-500, 501): x = i / 10. y = fx(x) fxplot.points.append((x, y)) soln_graph.graph.add_plot(fxplot) if self.solutions: plot = MeshLinePlot(color=rgb('fff400')) xmin = float(round(self.solutions[0], 4)) xmax = float(xmin) ymin = fx(xmin) ymax = ymin xmin = xmin xmax = xmin Logger.info("Plotting") plotx = MeshLinePlot(color=next(colors)) plotx.points = [(float(x), fx(x)) for x in self.solutions] counter = len(self.solutions) while counter >= 3: Logger.info(counter) for index in range(min(3, counter)): x = round(float(self.solutions[index]), 4) y = round(float(fx(x)), 4) x = x xmin = float(min([xmin, x])) xmax = float(max([xmax, x])) ymin = float(min([ymin, y])) ymax = float(max([ymax, y])) plot.points.append((x, y)) counter = counter - 1 if len(plot.points) >= min(3, len(self.solutions)): Logger.debug(['pts', plot.points]) soln_graph.graph.add_plot(plot) plot = MeshLinePlot(color=next(colors)) self.solutions.pop(0) counter = len(self.solutions) break pad = 0.1 Logger.debug(plot.points) soln_graph.graph.xmin = round(xmin - pad, 1) soln_graph.graph.xmax = round(xmax + pad, 1) soln_graph.graph.ymin = round(ymin - pad, 2) soln_graph.graph.ymax = round(ymax + pad, 2) hbar = MeshLinePlot(color=[1, 1, 1, 1]) hbar.points.append((soln_graph.graph.xmin, 0)) hbar.points.append((soln_graph.graph.xmax, 0)) soln_graph.graph.add_plot(hbar) for x, y in plotx.points: vbar = MeshLinePlot(color=rgb('6d98e2')) vbar.points.append((x, 0)) vbar.points.append((x, y)) soln_graph.graph.add_plot(vbar)
from math import sin from kivy.garden.graph import Graph, MeshLinePlot graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, 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) plot = MeshLinePlot(color=[1, 0, 0, 1]) plot.points = [(x, sin(x / 10.)) for x in range(0, 101)] graph.add_plot(plot)
def start(self, displaytext, graph, param, xlabel, ylabel): xlabel.text = "None" ylabel.text = "None" global realtimegraph global SelectedDate, SortID, rtgraphupdate try: rtgraphupdate.event.set() rtgraphupdate.join() except: pass SelectedDate = datetime.datetime.now().date() try: SortID = descripID[(param.text[20:]).lower()] except: displaytext.text = "Choose the parameter from the dropdown box!" return if realtimegraph is None: global MeasureRTPlot, plot realtimegraph = graph plot = MeshLinePlot(color=[1, 1, 0, 1]) MeasureRTPlot = MeshLinePlot(color=[1, 0, 0, 1]) #For the marker realtimegraph.add_plot(plot) realtimegraph.add_plot(MeasureRTPlot) if not ConnFlag: displaytext.text = "Please hold. Connecting to database..." prompter = PromptSuccess(1, "PrompterConnection", connthread, displaytext) prompter.start() return global realtimedata realtimedata = self.SQL_select_data_date(SelectedDate) #print(realtimedata) if not realtimedata: displaytext.text = "Data is empty for date: " + str(SelectedDate) print("Data is empty for date: ", SelectedDate) return # data will result in [(minutes, param),(minutes, param),(minutes, param)] global Outdata, ymin, ymax, xmin, xmax Outdata, ymin, ymax, xmin, xmax = self.dataConvert( realtimedata, SortID, 100) # Set initial graph axis to suit data realtimegraph.xmin = xmin realtimegraph.ymin = ymin realtimegraph.xmax = xmax realtimegraph.ymax = ymax realtimegraph.ylabel = param.text[20:] # Plot plot1 with the given data as points displaytext.text = " " plot.points = Outdata try: rtgraphupdate.event.set() rtgraphupdate.join() except: pass rtgraphupdate = RTGraphUpdateThread(1, "RTGraphUpdate", realtimegraph, plot, 0.5) rtgraphupdate.start()
def start(self, displaytext, graph, year, month, day, param, xlabel, ylabel): xlabel.text = "None" ylabel.text = "None" try: if year.text == "": SelectedDate = datetime.datetime.now().date() year.text = str(SelectedDate.year) month.text = str(SelectedDate.month) day.text = str(SelectedDate.day) else: SelectedDate = datetime.date(int(str(year.text)), int(str(month.text)), int(str(day.text))) print(SelectedDate) except: displaytext.text = "Date is in wrong format!" print("Date is in wrong format!") return try: SortID = descripID[(param.text[20:]).lower()] print(SortID) except: displaytext.text = "Choose the parameter from the dropdown box!" return global MeasurePlot, offlinegraph if offlinegraph is None: global plot, MeasurePlot plot = MeshLinePlot(color=[1, 1, 0, 1]) MeasurePlot = MeshLinePlot(color=[1, 0, 0, 1]) #For the marker graph.add_plot(plot) graph.add_plot(MeasurePlot) else: print("Clearing..") plot.points = [(0, 0)] if not ConnFlag: displaytext.text = "Please hold. Connecting to database..." prompter = PromptSuccess(1, "PrompterConnection", connthread, displaytext) prompter.start() return acquireddata = self.SQL_select_data_date(SelectedDate) #print(acquireddata) if not acquireddata: displaytext.text = "Data is empty for date: " + str(SelectedDate) print("Data is empty for date: ", SelectedDate) return # data will result in [(minutes, param),(minutes, param),(minutes, param)] global Outdata #Outdata, ymin, ymax, xmin, xmax = self.fulldataConvert(acquireddata, SortID) Outdata, ymin, ymax = self.fulldataConvert(acquireddata, SortID) # Set initial graph axis to suit data graph.xmin = 0 #xmin graph.ymin = ymin graph.xmax = 24 * 60 #xmax graph.ymax = ymax graph.ylabel = param.text[20:] # Plot plot1 with the given data as points displaytext.text = " " plot.points = Outdata