[Python] Assign Color to Specific Value in matplotlib through Python?

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página