Python 3D Plotting using matplotlib - Scatter Diagram for Data visualization and Data analysis

Sdílet
Vložit
  • čas přidán 10. 09. 2024
  • #techlearners
    Analysis of Run scoring Performance of a Cricket Batsman
    based on Cricket ball speed and swing
    Python Data Visualization using matplotlib
    Scatter 3D Plotting
    Prerequisites
    1 python setup
    2 installed numpy
    pip install numpy
    3 installed matplotlib
    pip install matplotlib
    Step 1 Create a python file scat3d.py
    Step 2 import necessary libraries
    import numpy as np
    import matplotlib.pyplot as plt
    Step 3 Create dataset
    runs = np.array([6, 6, 4, 2, 1, 4, 6, 4, 2, 1, 6, 6, 4, 2, 1, 4, 6, 4, 2, 1, 6, 6, 4, 2, 1, 4, 6, 4, 2, 1, 6, 6, 4, 2, 1, 4, 6, 4, 2, 1])
    speed = np.array([130, 132, 140, 150, 152, 142, 135, 132, 153, 140, 135, 134, 144, 156, 158, 146, 138, 139, 157, 146, 133, 134, 143, 152, 154, 140, 136, 131, 151, 144, 139, 133, 140, 150, 152, 142, 135, 130, 150, 145])
    swing = np.array([1, 1, 3, 4, 5, 2, 1, 2, 3, 5, 2, 2, 4, 3, 4, 5, 2, 1, 2, 4, 1, 1, 3, 4, 5, 2, 1, 2, 3, 5, 2, 2, 4, 3, 4, 5, 1, 2, 1, 5])
    Step 4 Create figure
    fig = plt.figure(figsize = (12, 6))
    Step 5 Set projection
    ax = plt.axes(projection ="3d")
    Step 6 Create grid
    ax.grid(b = True, color ='black',
    linestyle ='-.', linewidth = 0.5,
    alpha = 0.2)
    Step 7 Create colormap
    my_cmap = plt.get_cmap('hsv')
    Step 8 Create Scatter 3D Plot
    sctt = ax.scatter3D(speed, swing, runs,
    alpha = 0.9,
    c = (runs + speed + swing),
    cmap = my_cmap,
    marker ='^',
    )
    Step 9 Set title and Labels of plot
    plt.title("Analysis of run scoring performance in Cricket Match based on ball speed and swing")
    ax.set_xlabel('Speed of Cricket Ball in KMPH', fontweight ='bold')
    ax.set_ylabel('Swing of Cricket Ball', fontweight ='bold')
    ax.set_zlabel('Runs Scored by batsman', fontweight ='bold')
    Step 10 Set colorbar
    fig.colorbar(sctt, ax = ax)
    Step 11 Show plot
    plt.show()
    TECHLEARNERS BY NEERAJ SAXENA
    www.techlearner...

Komentáře •