how to use python to draw a 3d plot

An like shooting fish in a barrel introduction to 3D plotting with Matplotlib

George Seif

3D Besprinkle and Line Plots

3D plotting in Matplotlib starts by enabling the utility toolkit. Nosotros can enable this toolkit by importing the mplot3d library, which comes with your standard Matplotlib installation via pip. Just exist sure that your Matplotlib version is over 1.0.

                              from                mpl_toolkits                import                mplot3d

import numpy as np
import matplotlib.pyplot every bit plt

fig = plt.figure()
ax = plt.axes(projection="3d")

plt.show()

              fig = plt.figure()
ax = plt.axes(projection="3d")

z_line = np.linspace(0, xv, 1000)
x_line = np.cos(z_line)
y_line = np.sin(z_line)
ax.plot3D(x_line, y_line, z_line, 'gray')

z_points = fifteen * np.random.random(100)
x_points = np.cos(z_points) + 0.1 * np.random.randn(100)
y_points = np.sin(z_points) + 0.1 * np.random.randn(100)
ax.scatter3D(x_points, y_points, z_points, c=z_points, cmap='hsv');

plt.evidence()

Surface Plots

Surface plots tin can be great for visualising the relationships among three variables across the unabridged 3D landscape. They give a full structure and view as to how the value of each variable changes across the axes of the ii others.

              fig = plt.figure()
ax = plt.axes(projection="3d")
def z_function(x, y):
return np.sin(np.sqrt(x ** two + y ** two))

10 = np.linspace(-six, 6, 30)
y = np.linspace(-6, 6, 30)

X, Y = np.meshgrid(x, y)
Z = z_function(10, Y)

              fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot_wireframe(Ten, Y, Z, color='green')
ax.set_xlabel('10')
ax.set_ylabel('y')
ax.set_zlabel('z')

plt.show()

              ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, rstride=ane, cstride=one,
cmap='wintertime', edgecolor='none')
ax.set_title('surface');

3D Bar Plots

Bar plots are used quite ofttimes in information visualisation projects since they're able to convey information, usually some blazon of comparison, in a elementary and intuitive way. The beauty of 3D bar plots is that they maintain the simplicity of 2D bar plots while extending their chapters to represent comparative data.

              fig = plt.figure()
ax = plt.axes(projection="3d")

num_bars = 15
x_pos = random.sample(xrange(20), num_bars)
y_pos = random.sample(xrange(20), num_bars)
z_pos = [0] * num_bars
x_size = np.ones(num_bars)
y_size = np.ones(num_bars)
z_size = random.sample(xrange(twenty), num_bars)

ax.bar3d(x_pos, y_pos, z_pos, x_size, y_size, z_size, color='aqua')
plt.show()

lawsonbruse1971.blogspot.com

Source: https://towardsdatascience.com/an-easy-introduction-to-3d-plotting-with-matplotlib-801561999725

0 Response to "how to use python to draw a 3d plot"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel