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

Veröffentlicht am: 02 Mai 2024
auf dem Kanal: Techlearners By Neeraj Saxena
231
1

#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
http://www.techlearners.co.in


Auf dieser Seite können Sie das Online-Video Python 3D Plotting using matplotlib - Scatter Diagram for Data visualization and Data analysis mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Techlearners By Neeraj Saxena 02 Mai 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 231 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!