Python draws a 3D scatterplot with multiple colors

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
plt.style.use('seaborn-darkgrid')

# Make data
np.random.seed(19680801)
n = 100
rng = np.random.default_rng()
xs = rng.uniform(23, 32, n)
ys = rng.uniform(0, 100, n)
zs = rng.uniform(-50, -25, n)

# Plot
fig, ax = plt.subplots(subplot_kw={
    
    "projection": "3d"})
ax.scatter(xs, ys, zs,color='red')

ax.set(xticklabels=[],
       yticklabels=[],
       zticklabels=[])

plt.show()

insert image description here

ax.scatter(xs, ys, zs,color='teal')

insert image description here

ax.scatter(xs, ys, zs,color='purple')

insert image description here

ax.scatter(xs, ys, zs,color='maroon')

insert image description here
References: https://matplotlib.org/stable/plot_types/3D/scatter3d_simple.html

Guess you like

Origin blog.csdn.net/m0_38127487/article/details/132186140