def add_rsi_series(iw, ws, dates, ta, parent): values = ta.rsi(iw, ws) dpg.add_line_series(dates, values, label='RSI', parent=parent) dpg.add_button(label="Delete Series", user_data=dpg.last_item(), parent=dpg.last_item(), callback=lambda s, a, u: dpg.delete_item(u))
def plot_perf(plot_axis): (names, series) = load_perf("game.log") index = 1 + 3 * len(names) for (name, data) in series.items(): xs = [pair[0] for pair in data] ys = [pair[1] + (index / 2) for pair in data] dpg.add_line_series(xs, ys, label=name, parent=plot_axis) #, weight=2, fill=[255, 0, 0, 100]) index -= 3
def add_ema_series(n, dates, parent, ta): ema_dates = dates[n - 1:] ema_values = ta.ema(n).to_list()[n - 1:] dpg.add_line_series(ema_dates, ema_values, label='EMA-' + str(n), parent=parent) dpg.add_button(label="Delete Series", user_data=dpg.last_item(), parent=dpg.last_item(), callback=lambda s, a, u: dpg.delete_item(u))
def execute(self): x_axis_id = self.x_axis y_axis_id = self.y_axis x_orig_data = self._input_attributes[0].get_data() y_orig_data = self._input_attributes[1].get_data() dpg.add_line_series(x_orig_data, y_orig_data, parent=y_axis_id) dpg.fit_axis_data(x_axis_id) dpg.fit_axis_data(y_axis_id) self.finish()
def show_2d_plot(): global data global buffer global dpg_ids global initialised_plots if buffer == -1: length_to_show = data.shape[-1] else: length_to_show = buffer assert len( data.shape) > 1, ('The Data provided to a Multi Pane Plot must be 2D') number_of_lines = data.shape[0] if not initialised_plots: for n in np.arange(number_of_lines): dpg_ids["Plot {}".format(n)] = \ dpg.add_plot(label="Plot {}".format(n), height=int(800 / data.shape[0]), width=1030, show=True, parent=dpg_ids['Visualisation']) dpg_ids['x_axis {}'.format(n)] = \ dpg.add_plot_axis(dpg.mvXAxis, label='Data index', parent=dpg_ids["Plot {}".format(n)]) dpg_ids['y_axis {}'.format(n)] = \ dpg.add_plot_axis(dpg.mvYAxis, label='Data[{}]'.format(n), parent=dpg_ids["Plot {}".format(n)]) dpg_ids['Plot line {}'.format(n)] = dpg.add_line_series( np.arange(length_to_show), data[n:length_to_show], parent=dpg_ids['y_axis {}'.format(n)]) initialised_plots = True for n in np.arange(number_of_lines): dpg.set_value(dpg_ids['Plot line {}'.format(n)], [np.arange(length_to_show), data[n, :length_to_show]])
def show_1d_plot(): global data global buffer global dpg_ids global initialised_plots if buffer == -1: length_to_show = data.shape[-1] else: length_to_show = buffer number_of_lines = 1 if len(data.shape) > 1: number_of_lines = data.shape[0] if not initialised_plots: for n in np.arange(0, number_of_lines): dpg_ids['Plot line {}'.format(n)] = dpg.add_line_series( np.arange(length_to_show), data[n:length_to_show], parent=dpg_ids['y_axis']) initialised_plots = True if number_of_lines > 1: for n in np.arange(number_of_lines): dpg.set_value(dpg_ids['Plot line {}'.format(n)], [np.arange(length_to_show), data[n:length_to_show]]) else: dpg.set_value(dpg_ids['Plot line {}'.format(0)], [np.arange(length_to_show), data[:length_to_show]]) dpg.fit_axis_data(dpg_ids['x_axis'])
for name, deltas in all_deltas.items(): # create plot with dpg.plot(label=f"{name} deltas", height=200, width=900): # optionally create legend dpg.add_plot_legend() # REQUIRED: create x and y axes dpg.add_plot_axis(dpg.mvXAxis, label="x") dpg.set_axis_limits(dpg.last_item(), 0, len(x_coords)) dpg.add_plot_axis(dpg.mvYAxis, label="y") dpg.set_axis_limits(dpg.last_item(), -1, 1) # series belong to a y axis dpg.add_line_series(x_coords[:len(deltas)], deltas, label=f'{name}', parent=dpg.last_item(), id=f'{name}_deltas') log_lock = RLock() def cb_state(state_msg): with log_lock: for name, velocity in zip(state_msg.name, state_msg.velocity): if name in last_command and name in all_deltas: delta = last_command[name] - velocity all_deltas[name].append(delta) if len(all_deltas[name]) > len(x_coords): all_deltas[name] = all_deltas[name][-len(x_coords):] dpg.set_value(f'{name}_deltas', [x_coords[:len(all_deltas[name])], all_deltas[name]]) def cb_control(control_msg):
# because plots are containers plots will propagate themes with dpg.theme() as our_plot_theme: dpg.add_theme_color(dpg.mvPlotCol_PlotBg, (100, 0, 0, 50), category=dpg.mvThemeCat_Plots) dpg.add_theme_color(dpg.mvPlotCol_Line, (0, 255, 0, 255), category=dpg.mvThemeCat_Plots) dpg.add_theme_color(dpg.mvPlotCol_XAxis, (0, 255, 255, 255), category=dpg.mvThemeCat_Plots) with dpg.theme() as series_theme: dpg.add_theme_color(dpg.mvPlotCol_Line, (150, 0, 100, 255), category=dpg.mvThemeCat_Plots) with dpg.window(label="Tutorial"): # create plot with dpg.plot(label="Line Series", height=400, width=400) as plot: # REQUIRED: create x and y axes dpg.add_plot_axis(dpg.mvXAxis, label="x") axis_y = dpg.add_plot_axis(dpg.mvYAxis, label="y") # series belong to a y axis our_series = dpg.add_line_series((0, 1), (.5, .75), label="straight line", parent=axis_y) dpg.set_item_theme(plot, our_plot_theme) dpg.set_item_theme(our_series, series_theme) dpg.start_dearpygui()
def setUp(self): dpg.create_context() with dpg.window() as self.window_id: def testy(sender, app, user): print(f"Sender: {dpg.get_item_type(sender)} {sender}, App Data: {app}, User Data:{user}") # Menus with dpg.menu_bar() as menu_bar: dpg.add_menu_item(label="menu item", payload_type="str", drop_callback=testy) with dpg.menu(label="menu", payload_type="str", drop_callback=testy): dpg.add_menu_item(label="menu item") # basic with dpg.collapsing_header(label="basic") as basic: dpg.add_image(dpg.mvFontAtlas) dpg.add_image_button(dpg.mvFontAtlas) dpg.add_text("this is a text widget") dpg.add_checkbox(label="checkbox") dpg.add_button(label="button") dpg.add_input_float(label="input float") dpg.add_input_floatx(label="input floatx") dpg.add_drag_int(label="drag int") dpg.add_drag_intx(label="drag intx") dpg.add_input_text(label="input text") dpg.add_slider_float(label="slider float") dpg.add_slider_floatx(label="slider floatx") dpg.add_listbox(label="listbox") dpg.add_selectable(label="selectable") dpg.add_radio_button(["item 1", "item 2"],label="radio button") # color with dpg.collapsing_header(label="color") as color: with dpg.group() as color: dpg.add_color_button([255,0,0,255]) dpg.add_color_edit([255,0,0,255]) dpg.add_colormap_button(label="Colormap Button 1") dpg.add_color_picker((255, 0, 255, 255), label="Color Picker", width=200) dpg.add_colormap_slider(label="Colormap Slider 1", default_value=0.5, payload_type="str", drop_callback=testy) dpg.add_colormap_scale(label="Colormap Spectral", min_scale=-100, max_scale=150, payload_type="str", drop_callback=testy) # containers with dpg.collapsing_header(label="containers"): with dpg.group() as containers: with dpg.collapsing_header(): btn = dpg.add_button() with dpg.group(width=150): dpg.add_button() with dpg.tree_node(): dpg.add_button() with dpg.child_window(width=150, height=100, payload_type="str", drop_callback=testy): pass # tab stuff with dpg.collapsing_header(label="tab bars"): with dpg.tab_bar(): with dpg.tab(label="tab", payload_type="str", drop_callback=testy): pass dpg.add_tab_button(label="tab button", payload_type="str", drop_callback=testy, drag_callback=testy) with dpg.drag_payload(parent=dpg.last_item(), drop_data="dropped", drag_data="dragged", user_data="user data", payload_type="str"): dpg.add_text(dpg.get_item_type(dpg.last_item())) dpg.add_text(f"Item ID: {dpg.last_item()}") # custom with dpg.collapsing_header(label="custom"): with dpg.group() as custom: dpg.add_date_picker() dpg.add_knob_float() dpg.add_3d_slider() dpg.add_time_picker() dpg.add_loading_indicator(payload_type="str", drop_callback=testy) # misc with dpg.collapsing_header(label="misc"): with dpg.group() as misc: dpg.add_progress_bar(label="progress bar", default_value=.5) # node with dpg.collapsing_header(label="node"): with dpg.node_editor() as node: with dpg.node(pos=[20,20], draggable=False): pass with dpg.node(pos=[100,100], draggable=False): pass # plots with dpg.collapsing_header(label="plot") as plot: with dpg.plot(): dpg.add_plot_legend(payload_type="str", drop_callback=testy) dpg.add_plot_axis(dpg.mvXAxis, label="x", payload_type="str", drop_callback=testy) with dpg.plot_axis(dpg.mvYAxis, label="y", payload_type="str", drop_callback=testy): dpg.add_line_series([0,1,2,3,4,5], [0,1,2,3,4,5], label="data") self.test_bind_items = dpg.get_item_children(basic, slot=1) self.test_bind_items += dpg.get_item_children(color, slot=1) self.test_bind_items += dpg.get_item_children(containers, slot=1) self.test_bind_items += dpg.get_item_children(custom, slot=1) self.test_bind_items += dpg.get_item_children(misc, slot=1) self.test_bind_items += dpg.get_item_children(node, slot=1) self.test_bind_items += dpg.get_item_children(plot, slot=1) dpg.setup_dearpygui()
with dpg.window() as main_window: pass with dpg.window(id='Ploter', label="simple plot", no_resize=True, no_title_bar=True, no_move=True): with dpg.plot(id='Graph', label="Plot Acelerometro", height=300, width=400, anti_aliased=True): dpg.add_plot_legend() dpg.add_plot_axis(dpg.mvXAxis, label="Tempo", id='x_axis') dpg.set_axis_limits("x_axis", 0, 2*3.1415) dpg.add_plot_axis(dpg.mvYAxis, label="Valores XYZ", id="y_axis") #dpg.set_axis_limits('y_axis', -1.25,1.25) dpg.add_line_series([], [], label="X_value", id="X_value", parent="y_axis") dpg.add_line_series([], [], label="Y_value", id="Y_value", parent="y_axis") dpg.add_line_series([], [], label="Z_value", id="Z_value", parent="y_axis") def resize_group( sender, data, user ): dpg.configure_item('Ploter', height = data[1], width = data[0] ) dpg.configure_item('Graph', height = data[1]*0.9, width = data[0]*0.9, pos=[ data[0]*0.05, data[1]*0.05] ) dpg.setup_viewport() dpg.set_primary_window ( main_window, True ) dpg.set_viewport_min_height( height = 700 ) dpg.set_viewport_min_width ( width = 800 ) dpg.set_viewport_title ( title = 'Ploter Acelerometro' )