Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'clear plot' button #56

Open
rbaltrusch opened this issue Jun 22, 2024 · 2 comments
Open

Add 'clear plot' button #56

rbaltrusch opened this issue Jun 22, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed python Pull requests that update Python code

Comments

@rbaltrusch
Copy link
Owner

Add 'clear plot' button. Currently, the only way to clear plots of previous runs is to restart the GUI.

@rbaltrusch rbaltrusch added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers python Pull requests that update Python code labels Jun 22, 2024
@ShubhamKalsekar
Copy link

Install
pip install matplotlib ipywidgets

Create a Plot with a "Clear Plot" Button

import matplotlib.pyplot as plt
from ipywidgets import Button, VBox
from IPython.display import display

fig, ax = plt.subplots() #figure and axis

x = [1, 2, 3, 4, 5] #some initial plot data
y = [1, 4, 2, 3, 5]
line, = ax.plot(x, y)

def clear_plot(b):
ax.cla() # Clearing the current axis
fig.canvas.draw() # Redraw the figure

clear_button = Button(description="Clear Plot") #Create a button and set the function to on click
clear_button.on_click(clear_plot)

display(VBox([clear_button, fig.canvas])) #showing the button

Reference
https://www.activestate.com/resources/quick-reads/how-to-clear-a-plot-in-python/

@rbaltrusch
Copy link
Owner Author

rbaltrusch commented Jun 27, 2024

Hi @ShubhamKalsekar, thanks for your contribution. Can you integrate the code for this button into the existing gui and send a PR my way? Thanks 👍 Let me know if you need any help :)

PS: I would prefer not to add any extra dependencies to the project, I believe the current dependencies matplotlib and tkinter should suffice for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed python Pull requests that update Python code
Projects
None yet
Development

No branches or pull requests

2 participants