Matplotlib Slider Not Working When Called From A Function
I have the following code, which shows a graph with a slinding bar from matplotlib.widgets import Slider import matplotlib.pyplot as plt from numpy import arange, sin,
Solution 1:
Based on this you need to keep the sliders around globally.
Your example would only need to be slightly adjusted:
def myplot():
(... same code as above)
return szoom
keep_sliders = myplot()
Solution 2:
Okay, here is my working version with some improvements (e.g. lambda):
Baca Juga
- How To Import Word2vec Into Tensorflow Seq2seq Model?
- Pyqt5 Cannot Update Progress Bar From Thread And Received The Error "cannot Create Children For A Parent That Is In A Different Thread"
- Spyder 4 Is Not Displaying Plots And Displays Message Like This 'uncheck "mute Inline Plotting" Under The Plots Pane Options Menu.'
from matplotlib.widgets import Slider
import matplotlib.pyplot as plt
from numpy import arange, sin, pi
def myplot():
t = arange(0.0, 10.0, 0.01)
fig = plt.figure(figsize=[30, 20])
ax = plt.subplot(111)
plt.tight_layout()
plt.plot(t, sin(t * 10))
plt.ylim((-2, 2))
plt.xlim((0, 1))
axzoom = plt.axes([0.15, 0.05, 0.65, 0.03])
szoom = Slider(axzoom, 'Window', 1, 2)
szoom.on_changed(lambda val: ax.set_xlim([val, val + 1]))
fig.canvas.draw_idle()
plt.show()
myplot()
Post a Comment for "Matplotlib Slider Not Working When Called From A Function"