0

I have a dictionary with this RGB arrays:

colors = {"blue": [
            [0  ,128,255],
            [0  ,102,204],
            [0  ,76 ,153],
            [102,102,255],
            [51 ,51 ,255],
            [0  ,0  ,255],
            [0  ,0  ,204],
            [42, 81, 122],
            [60, 108, 191]   
            ]
           }

Is there some function on Matplotlib that allows me to easily plot these colors (each array represents an RGB code) all together in one plot?

1 Answer 1

1

Yes, you can pass RGB/RGBA values to (at least some) plotting functions in matplotlib. Here's an example with your input:

import matplotlib.pyplot as plt
import numpy as np

colors = {"blue": [
            [0  ,128,255],
            [0  ,102,204],
            [0  ,76 ,153],
            [102,102,255],
            [51 ,51 ,255],
            [0  ,0  ,255],
            [0  ,0  ,204],
            [42, 81, 122],
            [60, 108, 191]   
            ]
           }
# access the colors, scale them to be 0-1
blues = np.array(colors['blue']) / 255

# create figure and data
fig, ax = plt.subplots()
x = range(len(blues))

# plot, using one color for each point
ax.scatter(x, x, c=blues)

enter image description here

See the docs for the c parameter (in the case of a scatter plot).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.