Skip to content Skip to sidebar Skip to footer

3d Scatter Plot With Color Gradient Where Color Depends On Count

I have dataframe with points which include x, y and z coordinate of the point and 'count', which is number between 1 and 187 for each data point. I would like to associate 'count'

Solution 1:

I recommend you take a tour through these posts on matplotlib:

With that in mind I made the following:

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

#%% Generate mock data
number_of_datapoints = 30
x = np.random.rand(number_of_datapoints)
y = np.random.rand(number_of_datapoints)
z = np.random.rand(number_of_datapoints)

count_min = 1
count_max = 187
data = np.random.randint(count_min, count_max, number_of_datapoints) # these are your counts

#%% Create Color Map
colormap = plt.get_cmap("YlOrRd")
norm = matplotlib.colors.Normalize(vmin=min(data), vmax=max(data))

#%% 3D Plot
fig = plt.figure()
ax3D = fig.add_subplot(111, projection='3d')
ax3D.scatter(x, y, z, s=10, c=colormap(norm(data)), marker='o')  
plt.show()

You may also be interested in colorspacious


Post a Comment for "3d Scatter Plot With Color Gradient Where Color Depends On Count"