0

I have a simple widget that modifies a plot, here is the definition:

#Plot function
def plf(x,lm,ls):
    plt.plot(x[lm:ls],np.sin(x)[lm:ls])

this function takes a list x an plot sin(x), lm and ls controls the number of data that is ploted, the problem is when i try to plot a determinated list of data, for example

list = [1,2,3,4,5,6,7,8,9]

and if i try

interact(plf,x=list,lm=(0,max(x)//2,1),ls=(max(x)//2,max(x),1))

throws me the error:

NameError: name 'x' is not defined

so, how can i define x so it can be any list that i want?

1 Answer 1

3

Is this what you are trying to do?

%matplotlib inline
from IPython.html.widgets import interact, fixed
import matplotlib.pyplot as plt
import numpy as np

def plf(x,lm,ls):
    plt.plot(x[lm:ls],np.sin(x)[lm:ls])

data = [1,2,3,4,5,6,7,8,9]
max_lm = max(data)//2
max_ls = max(data)

interact(plf,x=fixed(data),lm=(0,max_lm,1),ls=(max_lm, max_ls,1))
Sign up to request clarification or add additional context in comments.

1 Comment

Ohhh thaks, this is exactly what i wanted

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.