Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib 3D scatter plot no facecolor

I have been struggling to find how to make 3d scatter plots in matplotlib with only marker edgecolor and no marker facecolor. Something like hollow markers, like matlab does.

Explanatory picture: https://i.sstatic.net/LnnOa.jpg

Until now, all I have been able to do is something like this: http://ceng.mugla.edu.tr/sharedoc/python-matplotlib-doc-1.0.1/html/_images/scatter3d_demo.png

Which is far from ideal, based on the number of samples I have to visualize.

Has anybody managed to do this?

like image 666
Fotis Avatar asked Oct 18 '25 15:10

Fotis


1 Answers

You can set the edgecolor and facecolor separately, like this:

enter image description here

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

def randrange(n, vmin, vmax):
    return (vmax-vmin)*np.random.rand(n) + vmin

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
    xs = randrange(n, 23, 32)
    ys = randrange(n, 0, 100)
    zs = randrange(n, zl, zh)
    ax.scatter(xs, ys, zs, facecolor=(0,0,0,0), s=100, marker=m, edgecolor=c)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

There are several ways to set the face color to transparent, see here.

like image 72
tom10 Avatar answered Oct 21 '25 06:10

tom10