3D interactive Graph Animation in Jupyter Notebook

3D interactive Graph Animation in Jupyter Notebook 

In this blog we are going to learn how to make 3D interactive graph animation in jupyter notebook.We are going to use modules ipywidgets to make interactive play button on our jupyter notebook ,mpl_toolkits to plot our 3D graph in jupyter notebook , matplotlib to plot the graph , numpy to use mathematical functions.
First we are going to import all the modules mentioned above
  • Now we have to define  a function in my case i am calling it theta and define a parameter t . Here the value of t change do the animation.
  • Now we will define the size of the graph in jupyter notebook in my case its figsize is  (10,15) which is satisfied and look good enough
  • We will define ax (meaning axis parameter ) and write projection  = '3d' to make sure that we are doing work in 3d workspace
  • Now we will define all the parameter that are basically going to plot in our 3d graph and aniamation . Here in z you can see i have types z = np.linspace(0,t,500) it basically means that z value start from 0 and end at t and There are 500 intervals between them.
  • Then we have defined x and y parameters that basically plot points  in x and y axis.
  • After we will our 3D plot function form mpl_toolkits to plot our 3D graph
  • At the end we will define our widgets to in the widgets you have to define function , parameter of the function that we are going to animate .Min and maximum value upto whcih our parmeter will. You can also define step size if you want but in my case i already did in z so i am not defninig it.
  • For any kinds of doubts and query please comment

import ipywidgets as widgets
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt

def theta (t):
    fig = plt.figure(figsize=(10,15))
    ax = plt.axes(projection ='3d')
    z  = np.linspace(0,t,500)
    x = np.sin(z)
    y = np.cos(z)
    ax.plot3D(x,y,z,'red')
    plt.show()
widgets.interact(theta , t= widgets.Play(min=0,max =15));




Blog : 2D Graph animation in Jupyter Notebook

Post a Comment

0 Comments