Python Forum
How do I map a list of values to specified colors?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I map a list of values to specified colors?
#1
Here is what I want to do:
a list of 19 values:
[-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, 0]
I would like the color grey gradual from white to black in the order in the list. How can I do that?
or else, if I can specify each different color to each different values, that is also ok.

Thanks.
Reply
#2
what have you tried?
Reply
#3
Thanks, Larz60+, What I am thinking about is mapping the list
[-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, -8, 8, -9, 9, 0] to another list
[255//19*i for i in range(19)] first
and then use
plt.imshow(arr, cmap='gray', vmin=0, vmax=255//19*19)
plt.show()
to show the array

I felt this method is not direct. Is there any better method, I mean directly assign a color to that number in the original list.

Thank you very much!
Reply
#4
is this what you are looking for?
>>> import numpy as np
>>> delta = 0.025
>>> x = y = np.arange(-3.0, 3.0, delta)
>>> x
array([-3.0000000e+00, -2.9750000e+00, -2.9500000e+00, -2.9250000e+00,
       -2.9000000e+00, -2.8750000e+00, -2.8500000e+00, -2.8250000e+00,
       -2.8000000e+00, -2.7750000e+00, -2.7500000e+00, -2.7250000e+00,
       -2.7000000e+00, -2.6750000e+00, -2.6500000e+00, -2.6250000e+00,
       -2.6000000e+00, -2.5750000e+00, -2.5500000e+00, -2.5250000e+00,
       -2.5000000e+00, -2.4750000e+00, -2.4500000e+00, -2.4250000e+00,
       -2.4000000e+00, -2.3750000e+00, -2.3500000e+00, -2.3250000e+00,
       -2.3000000e+00, -2.2750000e+00, -2.2500000e+00, -2.2250000e+00,
       -2.2000000e+00, -2.1750000e+00, -2.1500000e+00, -2.1250000e+00,
       -2.1000000e+00, -2.0750000e+00, -2.0500000e+00, -2.0250000e+00,
       -2.0000000e+00, -1.9750000e+00, -1.9500000e+00, -1.9250000e+00,
       -1.9000000e+00, -1.8750000e+00, -1.8500000e+00, -1.8250000e+00,
       -1.8000000e+00, -1.7750000e+00, -1.7500000e+00, -1.7250000e+00,
       -1.7000000e+00, -1.6750000e+00, -1.6500000e+00, -1.6250000e+00,
       -1.6000000e+00, -1.5750000e+00, -1.5500000e+00, -1.5250000e+00,
       -1.5000000e+00, -1.4750000e+00, -1.4500000e+00, -1.4250000e+00,
       -1.4000000e+00, -1.3750000e+00, -1.3500000e+00, -1.3250000e+00,
       -1.3000000e+00, -1.2750000e+00, -1.2500000e+00, -1.2250000e+00,
       -1.2000000e+00, -1.1750000e+00, -1.1500000e+00, -1.1250000e+00,
       -1.1000000e+00, -1.0750000e+00, -1.0500000e+00, -1.0250000e+00,
       -1.0000000e+00, -9.7500000e-01, -9.5000000e-01, -9.2500000e-01,
       -9.0000000e-01, -8.7500000e-01, -8.5000000e-01, -8.2500000e-01,
       -8.0000000e-01, -7.7500000e-01, -7.5000000e-01, -7.2500000e-01,
       -7.0000000e-01, -6.7500000e-01, -6.5000000e-01, -6.2500000e-01,
       -6.0000000e-01, -5.7500000e-01, -5.5000000e-01, -5.2500000e-01,
       -5.0000000e-01, -4.7500000e-01, -4.5000000e-01, -4.2500000e-01,
       -4.0000000e-01, -3.7500000e-01, -3.5000000e-01, -3.2500000e-01,
       -3.0000000e-01, -2.7500000e-01, -2.5000000e-01, -2.2500000e-01,
       -2.0000000e-01, -1.7500000e-01, -1.5000000e-01, -1.2500000e-01,
       -1.0000000e-01, -7.5000000e-02, -5.0000000e-02, -2.5000000e-02,
       -1.0658141e-14,  2.5000000e-02,  5.0000000e-02,  7.5000000e-02,
        1.0000000e-01,  1.2500000e-01,  1.5000000e-01,  1.7500000e-01,
        2.0000000e-01,  2.2500000e-01,  2.5000000e-01,  2.7500000e-01,
        3.0000000e-01,  3.2500000e-01,  3.5000000e-01,  3.7500000e-01,
        4.0000000e-01,  4.2500000e-01,  4.5000000e-01,  4.7500000e-01,
        5.0000000e-01,  5.2500000e-01,  5.5000000e-01,  5.7500000e-01,
        6.0000000e-01,  6.2500000e-01,  6.5000000e-01,  6.7500000e-01,
        7.0000000e-01,  7.2500000e-01,  7.5000000e-01,  7.7500000e-01,
        8.0000000e-01,  8.2500000e-01,  8.5000000e-01,  8.7500000e-01,
        9.0000000e-01,  9.2500000e-01,  9.5000000e-01,  9.7500000e-01,
        1.0000000e+00,  1.0250000e+00,  1.0500000e+00,  1.0750000e+00,
        1.1000000e+00,  1.1250000e+00,  1.1500000e+00,  1.1750000e+00,
        1.2000000e+00,  1.2250000e+00,  1.2500000e+00,  1.2750000e+00,
        1.3000000e+00,  1.3250000e+00,  1.3500000e+00,  1.3750000e+00,
        1.4000000e+00,  1.4250000e+00,  1.4500000e+00,  1.4750000e+00,
        1.5000000e+00,  1.5250000e+00,  1.5500000e+00,  1.5750000e+00,
        1.6000000e+00,  1.6250000e+00,  1.6500000e+00,  1.6750000e+00,
        1.7000000e+00,  1.7250000e+00,  1.7500000e+00,  1.7750000e+00,
        1.8000000e+00,  1.8250000e+00,  1.8500000e+00,  1.8750000e+00,
        1.9000000e+00,  1.9250000e+00,  1.9500000e+00,  1.9750000e+00,
        2.0000000e+00,  2.0250000e+00,  2.0500000e+00,  2.0750000e+00,
        2.1000000e+00,  2.1250000e+00,  2.1500000e+00,  2.1750000e+00,
        2.2000000e+00,  2.2250000e+00,  2.2500000e+00,  2.2750000e+00,
        2.3000000e+00,  2.3250000e+00,  2.3500000e+00,  2.3750000e+00,
        2.4000000e+00,  2.4250000e+00,  2.4500000e+00,  2.4750000e+00,
        2.5000000e+00,  2.5250000e+00,  2.5500000e+00,  2.5750000e+00,
        2.6000000e+00,  2.6250000e+00,  2.6500000e+00,  2.6750000e+00,
        2.7000000e+00,  2.7250000e+00,  2.7500000e+00,  2.7750000e+00,
        2.8000000e+00,  2.8250000e+00,  2.8500000e+00,  2.8750000e+00,
        2.9000000e+00,  2.9250000e+00,  2.9500000e+00,  2.9750000e+00])
Reply
#5
Thanks MckJohan, but nope. What I want to do is to specify a certain value to a specified color, maybe through RGB values.
establish the connections like the following:
-1 ---------------> R200 G150 B0
1 ---------------> R....G....B...
...
Something like this, and then use the map to draw
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Count image's colors very fast flash77 18 1,292 Mar-05-2024, 06:12 PM
Last Post: deanhystad
  Copying the order of another list with identical values gohanhango 7 1,060 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Comparing List values to get indexes Edward_ 7 1,081 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  can openpyxl read font colors mperemsky 3 1,653 May-09-2023, 11:18 AM
Last Post: MindKeeper
  Adding values with reduce() function from the list of tuples kinimod 10 2,512 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,023 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  ANSI not working for change of text colors BliepMonster 10 3,245 Nov-10-2022, 09:28 AM
Last Post: BliepMonster
  How to do bar graph with positive and negative values different colors? Mark17 1 4,999 Jun-10-2022, 07:38 PM
Last Post: Mark17
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 14,768 Jan-19-2022, 08:33 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020