Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/19-Bonus Material - Introduction to GUIs/06-Custom Widget.ipynb
Views: 648
Custom Widget
Exploring the Lorenz System of Differential Equations
In this Notebook we explore the Lorenz system of differential equations:
This is one of the classic systems in non-linear differential equations. It exhibits a range of different behaviors as the parameters (, , ) are varied.
Imports
First, we import the needed things from IPython, NumPy, Matplotlib and SciPy. Check out the class Python for Data Science and Machine Learning Bootcamp if you're interested in learning more about this part of Python!
Computing the trajectories and plotting the result
We define a function that can integrate the differential equations numerically and then plot the solutions. This function has arguments that control the parameters of the differential equation (, , ), the numerical integration (N
, max_time
) and the visualization (angle
).
Let's call the function once to view the solutions. For this set of parameters, we see the trajectories swirling around two points, called attractors.
Using IPython's interactive
function, we can explore how the trajectories behave as we change the various parameters.
The object returned by interactive
is a Widget
object and it has attributes that contain the current result and arguments:
After interacting with the system, we can take the result and perform further computations. In this case, we compute the average positions in , and .
Creating histograms of the average positions (across different trajectories) show that on average the trajectories swirl about the attractors.
NOTE: These will look different from the lecture version if you adjusted any of the sliders in the interactive
widget and changed the parameters.
Conclusion
Hopefully you've enjoyed using widgets in the Jupyter Notebook system and have begun to explore the other GUI possibilities for Python!