I am using Matplotlib in a class to view 3-Dimensional physical data.
I have a fiew sliders and radiobuttons, in which I can update the view on the data (eg. which layer, or what scale to use). This works perfectly fine in Pycharm when running a script. But when I use IPython in Pycharm, to work dynamically on my data, the widgets are either buggy (one of the sliders) or don't respond at all (all the other widgets). The tools of matplotlib for zooming and panning work totally fine though.
I am not quite sure, how to adress this problem, and what I can do for debugging. I beleave in both cases the backend is PyQt5.
There is one more difference, that might be a hint to a solution: the new opened matplotlib window, doesn't show the matplotlib logo, and is just white when run in Ipython.
Here is the minimal code, that reproduces the error. When run from pycharm, all is fine. When run in Pycharm debugger, aka IPython, the error.
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, RadioButtons
def plot():
def create_axes():
ax_slider1 = plt.axes([0.1, 0.1, 0.3, 0.1])
slider1 = Slider(label="", ax=ax_slider1, valmin=0, valmax=10)
ax_slider2 = plt.axes([0.1, 0.25, 0.3, 0.1])
slider2 = Slider(ax=ax_slider2, label="", valmin=0, valmax=10)
ax_button = plt.axes([0.1, 0.5, 0.15, 0.1])
button = RadioButtons(ax=ax_button, labels=["a", "b"])
return slider1, slider2, button
def update_axes():
good_slider.ax.set_xlim(1, 2)
fig.canvas.draw_idle()
def update_good_slider(offset):
print(offset)
update_axes()
def update_buttons(vlim_type):
print(vlim_type)
update_axes()
def update_bad_slider(factor):
print(factor)
update_axes()
fig, z_ax = plt.subplots()
fig.subplots_adjust(left=0.5)
good_slider, bad_slider, buttons = create_axes()
good_slider.on_changed(update_good_slider)
buttons.on_clicked(update_buttons)
bad_slider.on_changed(update_bad_slider)
plt.show()
plot()
Update I eventually got it working with help from here, and reprogramming my code to be more object orientated, and saving the plot() into a variable (see the commment from @medium-dimensional).