You can make this a little bit more efficient.
import numpy as np
import bqplot.pyplot as plt
from ipywidgets import interact, FloatSlider
fig = plt.figure()
xs = np.linspace(-3,3,100)
lines = plt.plot(xs, [])
def freq(a):
lines.y = np.sin(a * xs)
demo = interact(freq, a=FloatSlider(value=1, min=-3, max=3, step=0.01))
plt.ylim(-1.1,1.1)
plt.show()
also, passing
animation_duration=300
to figure() enables smooth transitions between different positions of the
lines.
Cheers,
On Sat, Jan 14, 2017 at 6:17 PM, <[email protected]> wrote:
> On Saturday, January 14, 2017 at 9:55:31 AM UTC-5, Sylvain Corlay wrote:
>
> The problem is that the rendering logic for matplotlib resides in the
>> backend. I would recommand using the "notebook" backend for matplotlib
>> which should improve the situation.
>>
>> Or you can use a plotting library for the notebook such as bqplot.
>>
>
> Thanks! the notebook backend seemed much worse. bqplot seems very new and,
> I'm guessing that it will be the way to work with 2D graphics in the
> notebook. For the record, I was able to piece together the following after
> a little fiddling:
>
> import numpy as np
> from bqplot import pyplot as plt
> from ipywidgets import interact, FloatSlider
>
> fig = plt.figure(1)
> def myplot(a):
> xs = np.linspace(-3,3,100)
> ys = np.sin(a*xs)
> if fig.marks == []:
> plt.plot(xs,ys)
> else:
> fig.marks[0].y = ys
> demo = interact(myplot, a=FloatSlider(value=1, min=-3, max=3, step=0.01))
> plt.ylim(-1.1,1.1)
> plt.show()
>
> This seems to work quite well.
>
> Thanks again!
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jupyter/1d4935fd-b035-4c7f-bbf7-8aa04ed20d4b%40googlegroups.com
> <https://groups.google.com/d/msgid/jupyter/1d4935fd-b035-4c7f-bbf7-8aa04ed20d4b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jupyter/CAK%3DPhk57BSEaHBdLiMEwb_qD%2B9R4%3DgtdSXUQaSxbNLYw4RZXqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.