Nova New Richardson
Nova New Richardson

Reputation: 1

Assign Color to Specific Value in matplotlib through Python?

I've got a chart produced in matplotlib that's basically a checkered grid. I've got four values and I want to assign each specific value a color on the grid. I do not want to use a colormap because that shows a gradient of values and that's not what I want. I have the values -1, 0, 1, 10. Is there a way to do this?

I don't think I can include the code without including the entirety of it because it's just a couple lines that relate to the grid but there's a lot of stuff that intermingles. Let's just say I have something that looks like

|1|-1|0|0|-1|1|

|0|1|1|-1|0|1|

|-10|1|1|0|1|1|

and because the way color maps work, the -10 is skewing the outcome because 1,0,-1 are all much closer to each other than -10. Instead I would like each number to just be assigned one color.

Upvotes: 0

Views: 3604

Answers (1)

Grant Williams
Grant Williams

Reputation: 1537

You could look into using a qualitative colormap from https://matplotlib.org/tutorials/colors/colormaps.html instead of one based on a gradient. They might fit your type of data more effectively.

Looking something like

enter image description here

Upvotes: 1

Related Questions