1

I'm using the scatter function from the matplotlib.pyplot library to visualize certain data in a 3D scatter plot. This function, Link to documentation , has an argument called 'c' which can be used to give the marker a particular color.

They note that the argument given for 'c' can be a RGB code stored in a 2D array. However when i try the code below it gives an error: "AttributeError: 'list' object has no attribute 'shape'".

My Question: Is it possible to give the markers in the scatter plot a custom color from the RGB format? And if it is, how can i achieve this?

Any help would be greatly appreciated.

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

RGB = [[255,255,255], [127,127,127], [10,10,10]]

r = []
g = []
b = []
a = 0
i = 0
j = 0
k = 0

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
mark = (".",",","o","v","^","<",">","1","2","3","4","8","s","p","P","*","h","H","+","x","X" ) # tuple for available markers from the matplotlib library

with open ('Color_Measurement_POCNR1_wolkjes.csv', 'r') as csvfile:
    plots = csv.reader(csvfile, delimiter = ';')
    for row in plots:
        if a == 1:
            r.append(float(row[6]))
            g.append(float(row[7]))
            b.append(float(row[8]))
            print("j = ", j, "r = ", r[j]," g = ", g[j], " b = ", b[j])
            ax.scatter(r[j], g[j], b[j], c= RGB[0], marker = mark[k] , s = 50)
            a = 0
            j += 1
            k += 1
        if row[0] == "Mean values":
            a += 1
      
ax.set_xlabel('R Label')
ax.set_ylabel('G Label')
ax.set_zlabel('B Label')

plt.show()
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Mauricio Paulusma
  • 43
  • 1
  • 1
  • 10

2 Answers2

0

They note that the argument given for 'c' can be a RGB code stored in a 2D array.

Exactly. However, in your code you use a 1D list. You may encapsulate this list in another list to make it 2D,

ax.scatter( ..., c= [RGB[0]])
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
0

The values in the list 'RGB' should range from 0 to 1 instead of 0 to 255.


This answer was posted as an edit to the question How to give the markers in the pyplot scatter plot a custom RGB color? by the OP Mauricio Paulusma under CC BY-SA 4.0.

vvvvv
  • 25,404
  • 19
  • 49
  • 81