Search code examples
pythonmatplotlibscatter-plotmplot3d

What is the full capacity of mplot3d's scatter's 'color' argument?


What are some examples of valid inputs for the c "color" argument of mplot3d's scatter?

i can input a single char basecolor such as 'r' and every datapoint is output in this color.

I can input an arrays of integers or floats, with the color output always being essentially a range of colors between yellow, green, and purple whether the range of my c values is 0< c <1 or 10< c <1000

If i try to input an array of hex values i receive the error

ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not ['0x1'...]

if i try to convert these integer/float values into indexes and then base colors, such that scatter is instead fed an array containing one of the "rgbcmykw" color strings such as ['r', 'g', 'b', 'b'...], i instead receive an exceptionally long Tkinter callback exception ending in:

TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'

My script is pretty complicated and essentially involves interpreting PDB coordinate data, so it may be simpler if i do not get into the details.

My question is, what are some examples of values for c that will actually be interpreted without error, besides an array of floats? I have been looking at the tutorials all day but they are quite difficult to interpret without example code.


Solution

  • Have you looked at https://matplotlib.org/stable/api/colors_api.html ?

    '0x1' is not a valid color

    'r' is a valid color, (1,0,0[,1.0]) is a valid color, '#f00' and #FF0000 are valid colors.

    If you pass an array of colors, then the number of elements in your array must match the number of points.