for i in range(n_frames):

    phi = phi_array[i]

    for j in range(n_points):

        r = r_array[j]

        for k in range(n_points):

            theta = theta_array[k]

            pos = np.array(sp2cart(r, theta, phi))

            V_Tensor[i][j][k] = myChargeDist.V(pos)

print('Finished calculating V_Tensor')

X, Y = np.meshgrid(r_array, theta_array * 180 / np.pi, indexing='ij')

fig = plt.figure(figsize=(16, 10))
ax = fig.gca(projection='3d')
surf = [ax.plot_surface(X, Y, V_Tensor[0], cmap='magma', rstride=1, cstride=1)]


def update(i):

    Axes3D.set_title(ax,
                     label=(r'$\phi$ = ' +
                            str(round(phi_array[i] * 180 / np.pi)) + r'$^o$'))
for i in range(n_points):

    x = x_array[i]

    for j in range(n_points):

        y = y_array[j]

        for k in range(n_points):

            z = z_array[k]

            pos = np.array([x, y, z])

            V_Tensor[i][j][k] = C_ChargeDist.V(pos) + H1.V(pos) + H2.V(
                pos) + H3.V(pos) + H4.V(pos)

print('Finished calculating V_Tensor')

X, Y, Z = np.meshgrid(x_array, y_array, z_array, indexing='ij')

V_Tensor[np.isinf(V_Tensor)] = np.nan

contour3d(X,
          Y,
          Z,
          V_Tensor,
          name='Equipotential surfaces for Methane Molecule',
          contours=50,
          opacity=0.5,
z_array = np.linspace(r_min, r_max, n_points)

V_Tensor = np.zeros((n_points, n_points, n_points))

print('Started calculating V_Tensor')

for i in range(n_points) :

    x = x_array[i]

    for j in range(n_points) :

        y = y_array[j]

        for k in range(n_points) :

            z = z_array[k]

            V_Tensor[i][j][k] = myChargeDist.V( np.array([x,y,z]) )

print('Finished calculating V_Tensor')

X, Y, Z = np.meshgrid( x_array, y_array, z_array, indexing='ij')

V_Tensor[ np.isinf(V_Tensor) ] = np.nan

contour3d(  X, Y, Z, V_Tensor,
            name='Equipotential surfaces for Octahedral Charge Distribution', 
            contours=50, opacity='0.5', colormap='magma')

waitkey = input()