Matplotlib is the most popular choice for data visualization. While initially developed for plotting 2-D charts like histograms, bar charts, scatter plots, line plots, etc.,
Three Dimensional Plotting
• Matplotlib
is the most popular choice for data visualization. While initially developed
for plotting 2-D charts like histograms, bar charts, scatter plots, line plots,
etc., Matplotlib has extended its capabilities to offer 3D plotting modules as
well.
• First
import the library :
importmatplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
• The
first one is a standard import statement for plotting using matplotlib, which
you would see for 2D plotting as well. The second import of the Axes3D class is
required for enabling 3D projections. It is, otherwise, not used anywhere else.
• Create
figure and axes
fig = plt.figure(figsize=(4,4))
ax = fig.add_subplot(111,
projection='3d')
Output:
Example :
fig=plt.figure(figsize=(8,8))
ax=plt.axes(projection='3d')
ax.grid()
t=np.arange(0,10*np.pi,np.pi/50)
x=np.sin(t)
y=np.cos(t)
ax.plot3D(x,y,t)
ax.set_title('3D
Parametric Plot')
# Set
axes label
ax.set_xlabel('x',labelpad=20)
ax.set_ylabel('y',
labelpad=20)
ax.set_zlabel('t',
labelpad=20)
plt.show()
Output:
Foundation of Data Science: Unit V: Data Visualization : Tag: : Matplotlib | Data Visualization - Three Dimensional Plotting
Foundation of Data Science
CS3352 3rd Semester CSE Dept | 2021 Regulation | 3rd Semester CSE Dept 2021 Regulation