0

I have a slider and a RadioButton on a plot (very similar to the one show here: https://matplotlib.org/3.1.1/gallery/widgets/slider_demo.html). If I change the Amp and Freq sliders and then hit reset, the plot goes back to its initial values. However, if I change red to blue and then hit reset, it stays on blue. How can I reset a RadioButton? I use the following to reset the slider:

def resetplt(event)
    svalueM.reset()

where svalueM is defined as:

svalueM = Slider(slider_M, 'M', smin, smax, valinit=sinit)
calmymail
  • 127
  • 8

1 Answers1

0

Add

radio.set_active(0)

to your reset function.

replace 0 with whatever value was set as active= in the creation of the RadioButtons

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75
  • Thank you very much. I look through MatPlotLib documentation and elsewhere and could not figure this out. Can you tell me where one finds answers to such questions. Thanks! – calmymail Dec 10 '19 at 00:42
  • "how to reset" can be rephrased as "how to programmatically change the value of a radio button back to its original setting". [Looking at the documentation](https://matplotlib.org/api/widgets_api.html?#matplotlib.widgets.RadioButtons) I can see that the initial value is set by the `active=` parameter in the constructor, and that there is a `set_active()` function that allows changing the selected button. – Diziet Asahi Dec 10 '19 at 09:55
  • Thanks, this is helpful. – calmymail Dec 10 '19 at 14:15
  • So, I now added a checkbutton and want to reset it. The documentation says "set_active(self, index)" so I put CheckPar.set_active('2 Hz'',0) and I get the error TypeError: set_active() takes 2 positional arguments but 3 were given. I'm confused. Can you shed some light onto this. – calmymail Dec 11 '19 at 02:38
  • You should probably ask another question because the situation is a bit more complicated for check boxes. But to solve your error, the syntax is `CheckPar.set_active(0)` to switch the state of the first check box – Diziet Asahi Dec 11 '19 at 07:53