Python Forum
3D Plotting in Matplotlib for Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D Plotting in Matplotlib for Python
#1
Hi everyone, I'm very new with Python. I found this code and I would like to change the color of a specific position in this 3d-matrix.

Thanks in advance,

Regards,


[Image: e1DQ6kA.png]

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



fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

z = [8,7,6,7,9,10,9,8,10,8,9,10,9,8,10,8,9,10,9,8,10,8,9,10]
x = [1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4]
y = [1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6]


ax.scatter(x, y, z, c='r', marker='o')
    

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

plt.show()
Reply
#2
As it could be seen from the official docs, c parameter in the scatter function could be a vector, consisting of
corresponding colors to each point.

# changes in your code
colored_inds = [10, 12, 15]  # points #10, 12 and 15 will be blue.
colors = ['r' if j not in colored_inds else 'b' for j in range(len(x))]
ax.scatter(x, y, z, c=colors, marker='o')
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020