Виджет imshow() не заменяет изображенияPython

Программы на Python
Anonymous
Виджет imshow() не заменяет изображения

Сообщение Anonymous »


I have a simple script that takes three inputs from users, adapts a path based on the input and displays an image based on the path. It all works fine except for the fact that after each slider adaption, a new plot is generated instead of replacing the old plot.

Placing the plt.figure outside of the update function does not help either. Any thoughts?

Code:

def update_plot(param1, param2, param3): # Choose image based on path img = cv2.imread(f'C:/Users/Jeff/Desktop/{param1}x{param2}y{param3}z.JPG') # Show plot plt.figure(figsize=(10, 12)) plt.axis('off') plt.imshow(img[...,::-1]) # Keep original colors instead of cv2 colors plt.show() # Create interactive widgets for each parameter param1_widget = widgets.IntSlider(value=1, min=1, max=9, step=2,description='Medium in mL/min', orientation='horizontal', readout=True) param2_widget = widgets.IntSlider(value=1, min=1, max=9, step=2,description='Gas in mL/min', orientation='horizontal', readout=True) param3_widget = widgets.IntSlider(value=1, min=1, max=9, step=2,description='Leistung in W', orientation='horizontal', readout=True) # Create a button to update the plot update_button = widgets.Button(description = "Apply spray settings") # Define the callback function for the button def on_button_clicked(b): update_plot(param1_widget.value, param2_widget.value, param3_widget.value) # Button clicked action update_button.on_click(on_button_clicked) # Display the widgets and button display(param1_widget, param2_widget, param3_widget, update_button) To reproduce the example, just save two .JPG images into a directory, adapt my path and name them like the example.


Источник: https://stackoverflow.com/questions/780 ... ing-images

Вернуться в «Python»