1

I have a very large data set and want the user to be able to slide along the axis to view sections of the data. I'm trying to leverage off of the slider example but I'm unsure of how to update the graph. Hoping someone can explain some of the behinds the scenes with this.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import Slider, Button, RadioButtons

fig = plt.figure()
ax = fig.add_subplot(111)
fig.subplots_adjust(left=0.25, bottom=0.25)
min0 = 0
max0 = 10

x = np.arange(10)
y = np.arange(10) 
im1 = plt.scatter(x,y, s=3, c=u'b', edgecolor='None',alpha=.75)
#most examples here return something iterable

plt.ylim([0,10])#initial limits

axcolor = 'lightgoldenrodyellow'
axmin = fig.add_axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axmax  = fig.add_axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)

smin = Slider(axmin, 'Min', 0, 10, valinit=min0)
smax = Slider(axmax, 'Max', 0, 10, valinit=max0)

def update(val):
    plt.ylim([smin.val,smax.val])
    ax.canvas.draw()#unsure on this
smin.on_changed(update)
smax.on_changed(update)

plt.show()

1 Answer 1

1

The graph updates itself when you set new limits. You just don't see this because you update wrong subplot. Just select right subplot to update:

def update(val):
    plt.subplot(111)
    plt.ylim([smin.val,smax.val])

(this work for me)

or maybe even:

def update(val):    
    plt.ylim([smin.val,smax.val])

plt.subplot(111)
smin.on_changed(update)
smax.on_changed(update)

if you don`t do anything with it elsewhere

UPD: also in matplotlib examples you can find fig.canvas.draw_idle()

Sign up to request clarification or add additional context in comments.

1 Comment

selecting the correct subplot fixes this: plt.subplot(111) Thank you for taking the time to look at this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.