Question: how to get 3d animation plots

dear sir here i am giving python code exicuting 3d plots but i cant plot animations like

i awant similar for 3d plots ,here is the python code: 

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from scipy.interpolate import Rbf

import warnings

warnings.filterwarnings('ignore')

 

# Replace this with your loaded DataFrame if needed

data = {

    'Nr': [1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4],

    'Nc': [0.1,0.12,0.14,0.16,0.18,0.2,0.22,0.24,0.26,0.28,0.3,0.32,0.34,0.36,0.38,0.4,0.42,0.44,0.46,0.48,0.5,0.13,0.15,0.25,0.35],

    'M': [1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5],

    'QG': [0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9],

    'wet_sin': [0.368706,0.413817,0.456854,0.496589,0.531781,0.561484,0.58529,0.60339,0.616457,0.625407,

                0.631193,0.63466,0.636489,0.637192,0.637136,0.636575,0.635684,0.634578,0.634578,0.632,

                0.630613,0.631344,0.629788,0.627838,0.625937],

    'dry_sin': [0.360048,0.405541,0.449704,0.491776,0.530905,0.566266,0.59721,0.623377,0.644747,0.661611,

                0.674485,0.683996,0.690788,0.695452,0.698496,0.700329,0.701272,0.701568,0.701568,0.700893,

                0.700148,0.70323,0.701991,0.699934,0.697904],

    'wet_cos': [0.336473,0.383123,0.428412,0.471134,0.509903,0.543472,0.57106,0.592545,0.608418,0.61956,

                0.626981,0.631632,0.634302,0.635597,0.635957,0.635691,0.635009,0.634053,0.634053,0.631668,

                0.630343,0.63112,0.629601,0.627681,0.625805],

    'dry_cos': [0.325553,0.37218,0.417942,0.462134,0.503895,0.542307,0.576549,0.606047,0.630576,0.650272,

                0.665563,0.677059,0.685431,0.691326,0.695313,0.697864,0.69935,0.700057,0.700057,0.69993,

                0.699368,0.702582,0.701455,0.699488,0.697528]

}

 

df = pd.DataFrame(data)

 

cases = [

    {'key': 'wet_sin', 'label': r'$\Theta(Y,\tau)$ Wet sin($\alpha=\pi/2$)', 'color': 'red', 'linestyle': '-'},

    {'key': 'dry_sin', 'label': r'$\Theta(Y,\tau)$ Dry sin($\alpha=\pi/2$)', 'color': 'cyan', 'linestyle': '--'},

    {'key': 'wet_cos', 'label': r'$\Theta(Y,\tau)$ Wet cos($\alpha=\pi/2$)', 'color': 'green', 'linestyle': ':'},

    {'key': 'dry_cos', 'label': r'$\Theta(Y,\tau)$ Dry cos($\alpha=\pi/2$)', 'color': 'yellow', 'linestyle': '-.'}

]

 

param_pairs = [('Nr', 'Nc'), ('Nr', 'M'), ('Nr', 'QG'), ('Nc', 'M'), ('Nc', 'QG'), ('M', 'QG')]

 

def plot_all_pairs(df, cases, pairs):

    for x_param, y_param in pairs:

        x = df[x_param].values

        y = df[y_param].values

        xi = np.linspace(x.min(), x.max(), 50)

        yi = np.linspace(y.min(), y.max(), 50)

        XI, YI = np.meshgrid(xi, yi)

 

        plt.figure(figsize=(16,6))

 

        # Contour subplot

        plt.subplot(1, 2, 1)

        all_z = np.concatenate([df[case['key']].values for case in cases])

        vmin, vmax = all_z.min(), all_z.max()

 

        for case in cases:

            z = df[case['key']].values

            rbf = Rbf(x, y, z, function='multiquadric', smooth=0.1)

            ZI = rbf(XI, YI)

            cset = plt.contourf(XI, YI, ZI, levels=15, cmap='coolwarm', vmin=vmin, vmax=vmax, alpha=0.3)

            CS = plt.contour(XI, YI, ZI, levels=10, colors=case['color'], linestyles=case['linestyle'])

            plt.clabel(CS, inline=True, fontsize=8, fmt='%.3f')

            plt.scatter(x, y, c=case['color'], label=case['label'], edgecolor='black', s=20, alpha=0.8, zorder=5)

 

        cb = plt.colorbar(cset, label=r'$\Theta(Y,\tau)$')

        plt.xlabel(x_param)

        plt.ylabel(y_param)

        plt.title('Contour Plot')

        plt.legend(loc='lower right', fontsize=10, frameon=True)

        plt.grid(True)

        plt.tight_layout()

 

        # 3D Surface subplot

        ax = plt.subplot(1, 2, 2, projection='3d')

        for case in cases:

            z = df[case['key']].values

            rbf = Rbf(x, y, z, function='multiquadric', smooth=0.1)

            ZI = rbf(XI, YI)

            ax.plot_surface(XI, YI, ZI, color=case['color'], alpha=0.5, edgecolor='none')

        ax.set_xlabel(x_param)

        ax.set_ylabel(y_param)

        ax.set_zlabel(r'$\Theta(Y,\tau)$', fontsize=12, labelpad=8)

        ax.view_init(elev=30, azim=135)

        ax.set_title('3D Response Surface')

        plt.suptitle(f'{x_param} vs {y_param} Triangular Fin Thermal Response', fontsize=16, y=1.02)

        plt.tight_layout(rect=[0, 0, 1, 0.95])

        plt.show()

 

plot_all_pairs(df, cases, param_pairs)

how to make animations in 3d visualisation. 

i have seen some plots in maple also for that reason i have posted this question here

 

Please Wait...