-
-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Update custom series plog #1885
Comments
Try use: Replace this:#The line below crash
dpg.set_value("demo_custom_series", [allGraphs[graph]['X'], allGraphs[graph]['Y'], 2]) To:#The line below crash
dpg.configure_item("demo_custom_series", x=new_x, y=new_y, channel_count=2) or:#The line below crash
dpg.configure_item("demo_custom_series", x=allGraphs[graph]['X'], y=allGraphs[graph]['Y'], channel_count=2) |
If my y_axis contains both custom plot and line series plot, how to delete all the plots? It crash when I do dpg.delete_item("y_axis", children_only=True), but works fine if I don't have the custom plot
|
I still have the same problem when I try to update both custom and add_line_series plot. Several bugs occurs:
|
(I also "removed" the output of the errors, I do not know how to fix them quickly and they do not seem to affect the program in any way. See NEW-2 comment) import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
def callback(sender, app_data):
_helper_data = app_data[0]
transformed_x = app_data[1]
transformed_y = app_data[2]
# transformed_y1 = app_data[3] # for channel = 3
# transformed_y2 = app_data[4] # for channel = 4
# transformed_y3 = app_data[5] # for channel = 5
mouse_x_plot_space = _helper_data["MouseX_PlotSpace"] # not used in this example
mouse_y_plot_space = _helper_data["MouseY_PlotSpace"] # not used in this example
mouse_x_pixel_space = _helper_data["MouseX_PixelSpace"]
mouse_y_pixel_space = _helper_data["MouseY_PixelSpace"]
################## NEW-2 ##################
try:
dpg.delete_item(sender, children_only=True, slot=2)
except Exception:
return
###########################################
dpg.push_container_stack(sender)
dpg.configure_item("demo_custom_series", tooltip=False)
for i in range(0, len(transformed_x)):
dpg.draw_text((transformed_x[i] + 15, transformed_y[i] - 15), str(i), size=20)
dpg.draw_circle((transformed_x[i], transformed_y[i]), 15, fill=(50 + i * 5, 50 + i * 50, 0, 255))
if mouse_x_pixel_space < transformed_x[i] + 15 and mouse_x_pixel_space > transformed_x[i] - 15 and mouse_y_pixel_space > transformed_y[i] - 15 and mouse_y_pixel_space < transformed_y[i] + 15:
dpg.draw_circle((transformed_x[i], transformed_y[i]), 30)
dpg.configure_item("demo_custom_series", tooltip=True)
dpg.set_value("custom_series_text", "Current Point: " + str(i))
dpg.pop_container_stack()
import random
def clear_y():
dpg.delete_item("y_axis", children_only=True, slot=1)
print('clear done')
def update_graph():
new_x = []
new_y = []
for i in range(10):
new_x.append(i)
new_y.append(random.randint(0, 500))
################## NEW ##################
clear_y()
with dpg.custom_series(new_x, new_y, 2, callback=callback, tag="demo_custom_series", parent='y_axis'): # added parameter parentparent
dpg.add_text("Current Point: ", tag="custom_series_text")
dpg.add_line_series(new_x, new_y, tag='series_line', parent='y_axis') # added parameter parent # new line series
dpg.fit_axis_data('y_axis')
#########################################
# dpg.configure_item("demo_custom_series", x=new_x, y=new_y)
# dpg.configure_item("series_line", x=new_x, y=new_y)
print('updated')
x_data = [0.0, 1.0, 2.0, 4.0, 5.0]
y_data = [0.0, 10.0, 20.0, 40.0, 50.0]
with dpg.window(label="Tutorial") as win:
dpg.add_button(label='update', callback=update_graph)
dpg.add_button(label='cleary', callback=clear_y)
dpg.add_text("Hover an item for a custom tooltip!")
with dpg.plot(label="Custom Series", height=400, width=-1):
dpg.add_plot_legend()
xaxis = dpg.add_plot_axis(dpg.mvXAxis)
with dpg.plot_axis(dpg.mvYAxis, tag='y_axis'):
with dpg.custom_series(x_data, y_data, 2, callback=callback, tag="demo_custom_series"):
dpg.add_text("Current Point: ", tag="custom_series_text")
dpg.add_line_series(x_data, y_data, tag='series_line') # new line series
dpg.fit_axis_data(dpg.top_container_stack())
with dpg.window(pos=(100, 0)):
dpg.add_button(label='update', callback=update_graph)
dpg.add_button(label='cleary', callback=clear_y)
dpg.set_primary_window(win, True)
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context() With "loop range to a higher number" it takes longer to find the problem (although I think the problem is in the callback, specifically in the for loop: draw_text, draw_circle) |
Okay. I see. Thank you for looking into that! My data have a size of 2048. It seems to plot fine but when I try to move or auto scale the graph it crash. Is there a way that I can use line_series only or scatter_series only to show the tooltip of at a specific point? My goal to view the exact x and y point at a point on the line. |
So I was able to fix the crashes at high values of the loop, but there was a problem with performance def callback(sender, app_data):
_helper_data = app_data[0]
transformed_x = app_data[1]
transformed_y = app_data[2]
# transformed_y1 = app_data[3] # for channel = 3
# transformed_y2 = app_data[4] # for channel = 4
# transformed_y3 = app_data[5] # for channel = 5
mouse_x_plot_space = _helper_data["MouseX_PlotSpace"] # not used in this example
mouse_y_plot_space = _helper_data["MouseY_PlotSpace"] # not used in this example
mouse_x_pixel_space = _helper_data["MouseX_PixelSpace"]
mouse_y_pixel_space = _helper_data["MouseY_PixelSpace"]
################## NEW-2 ##################
try:
dpg.delete_item(sender, children_only=True, slot=2)
except Exception:
return
###########################################
with dpg.mutex():
dpg.push_container_stack(sender)
dpg.configure_item("demo_custom_series", tooltip=False)
for i in range(0, len(transformed_x)):
dpg.draw_text((transformed_x[i] + 15, transformed_y[i] - 15), str(i), size=20)
dpg.draw_circle((transformed_x[i], transformed_y[i]), 15, fill=(50 + i * 5, 50 + i * 50, 0, 255))
if mouse_x_pixel_space < transformed_x[i] + 15 and mouse_x_pixel_space > transformed_x[i] - 15 and mouse_y_pixel_space > transformed_y[i] - 15 and mouse_y_pixel_space < transformed_y[i] + 15:
dpg.draw_circle((transformed_x[i], transformed_y[i]), 30)
dpg.configure_item("demo_custom_series", tooltip=True)
dpg.set_value("custom_series_text", "Current Point: " + str(i))
dpg.pop_container_stack() I think you should optimize the callback loop somehow. Maybe with threads or other means. I suggest you choose your own option by searching for a solution on the internet, since this is already a python question and there are many solutions. |
Check #1864. |
Thanks @Ivanzzzc for taking the time to look into that! So there is no way I can use add_line_series with tooltip to show the value ON the line? All I want is to have tooltip to show the value on the line. Maybe I can try to draw the line using the custom_series with the tooltip option instead of draw 2048 circles. And how can I use thread with dearpygui? I think I read it somewhere that dearpygui handles the thread differently and all the resources that I found is using the old dearpygui structure. |
Please take this to discord. |
Hi,
How do we I update the custom_series plot after it is created? Do I just do set_value to set the x and y? I tried but it crashed without error.
The text was updated successfully, but these errors were encountered: