Controlling the alpha value on a 3D scatter plot using Python and Matplotlib


To control the alpha value on a 3D scatter plot using Python and Matplotlib, we can set the facecolor and edgecolors value.

  • Set the figure size and adjust the padding between and around the subplots.
  • Create a new figure or activate an existing figure using figure() method.
  • Add an '~.axes.Axes' to the figure as part of a subplot arrangement.
  • Create x, y and z data points using numpy.
  • Plot x, y and z points using scatter() method.
  • Set the facecolors and edgecolors.
  • To display the figure, use show() method.

Example

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
x = np.random.sample(20)
y = np.random.sample(20)
z = np.random.sample(20)
s = ax.scatter(x, y, z, c="r")
s._set_facecolors, s._set_edgecolors = s.set_facecolors, s.set_edgecolors
plt.show()

Output

Updated on: 01-Jun-2021

480 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements