Skip to content

Commit

Permalink
main : added auto-fit axis limits to plot update example.
Browse files Browse the repository at this point in the history
  • Loading branch information
my1e5 committed Oct 10, 2023
1 parent 8dc02e1 commit 98079e1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plots/plot_update_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ def generate_data(m: float, c: float):
def update_plot():
data_x, data_y = generate_data(dpg.get_value("m_slider"), dpg.get_value("c_slider"))
dpg.configure_item('line', x=data_x, y=data_y)
if dpg.get_value("auto_fit_checkbox"):
dpg.fit_axis_data("xaxis")
dpg.fit_axis_data("yaxis")

with dpg.window():
with dpg.window(pos=(10,10)):
with dpg.plot(label="y = mx + c", height=400, width=500):
xaxis = dpg.add_plot_axis(dpg.mvXAxis, label="x")
yaxis = dpg.add_plot_axis(dpg.mvYAxis, label="y")
dpg.add_plot_axis(dpg.mvXAxis, label="x", tag="xaxis")
dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis")
data_x, data_y = generate_data(M, C)
dpg.add_line_series(data_x, data_y, tag='line', parent=yaxis)
dpg.add_line_series(data_x, data_y, tag='line', parent="yaxis")

dpg.add_slider_float(label="m", tag="m_slider", default_value=M, min_value=0, max_value=10, callback=update_plot)
dpg.add_slider_float(label="c", tag="c_slider", default_value=C, min_value=-50, max_value=50, callback=update_plot)
dpg.add_checkbox(label="Auto-fit axis limits", tag="auto_fit_checkbox", default_value=False)

dpg.create_viewport(width=900, height=600, title='Updating plot data')
dpg.setup_dearpygui()
Expand Down

0 comments on commit 98079e1

Please sign in to comment.