Search code examples
pythonmatplotlibscatter3d

Python Matplotlib: Shading 3D Scatter Plot


I have a scatter plot of a 3D point cloud (see picture). The green points actually form an extrusion in the shape of a star, the blue is a pentagon etc, but this is very difficult to see. So I would like to have some "shading" of the point clouds. It's possible to do this sort of thing for surfaces (like discussed here:

The code I have currently:

import sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()  # for plot styling

filename = sys.argv[1]
# flow_events = np.loadtxt(filename, comments='#')
flow_events = pd.read_csv(filename, delimiter = "\t", skiprows=1, names=["event_x", "event_y", "event_ts", "event_label"])
n_flow_events = flow_events.values

# start = int(n_flow_events.shape[0]/3.0)
end = int(n_flow_events.shape[0]/10.0*7)
start = 0
# end = n_flow_events.shape[0]

events = n_flow_events[start:end, :]

number_to_display = 5
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(events[0::number_to_display, 0], events[0::number_to_display, 1], events[0::number_to_display, 2], c=(events[0::number_to_display, 3]+4), s=4, cmap=plt.cm.brg)

ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('time [s]')

plt.show()

The point cloud


Solution

  • So this is not exactly a solution to the question I asked, but I ended up doing what mauve suggested: Point cloud caps in black