I'm plotting a 3D scatter plot using the function scatter and mplot3d. I'm choosing a single color for all points in the plot, but when drawn by matplotlib the transparency of the points is set relative to the distance from the camera. Is there any way to disable this feature?
I've tried setting the alpha kwarg to None/1 and also set vmin/vmax to 1 (in an attempt to force the color scaling to be a solid single color) with no luck. I didn't see any other likely options related to this setting in the scatter documentation.
Thanks!
Matplotlib allows you to regulate the transparency of a graph plot using the alpha attribute. By default, alpha=1. If you would like to form the graph plot more transparent, then you'll make alpha but 1, such as 0.5 or 0.25.
3D plotting in Matplotlib starts by enabling the utility toolkit. We can enable this toolkit by importing the mplot3d library, which comes with your standard Matplotlib installation via pip. Just be sure that your Matplotlib version is over 1.0. Now that our axes are created we can start plotting in 3D.
For Matplotlib 1.4+, the answer provided below by @fraxel is the best solution: call ax.scatter
with the argument depthshade=False
.
There is no arguments that can control this. Here is some hack method.
Disable set_edgecolors
and set_facecolors
method, so that mplot3d can't update the alpha part of the colors:
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(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_edgecolors = s.set_facecolors = lambda *args:None
ax.legend()
ax.set_xlim3d(0, 1)
ax.set_ylim3d(0, 1)
ax.set_zlim3d(0, 1)
plt.show()
If you want call set_edgecolors
and set_facecolors
methods later, you can backup these two methods before disable them:
s._set_facecolors, s._set_edgecolors = s.set_facecolors, s.set_edgecolors
ax.scatter(x, y, z, depthshade=0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With