Bottom Page

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.
Quote
#2
what have you tried?
Quote
#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!
Quote
#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])
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Grabbing comma separed values from SQLite and putting them in a list PythonNPC 8 300 Apr-10-2020, 02:39 PM
Last Post: buran
  Randomly assign values in List 1 to a value in List 2 Seneca260 7 773 Dec-16-2019, 12:57 PM
Last Post: BamBi25
  Why does this list of lists end up with the same values alehak 2 548 Jul-18-2019, 12:34 PM
Last Post: perfringo
  How to create a list with all values being zero 357mag 4 446 Jul-14-2019, 03:43 PM
Last Post: ThomasL
  Remove \n from list of values within a pandas columns klllmmm 2 2,048 Jun-24-2019, 05:16 AM
Last Post: klllmmm
  update values in list based on dictionary bunti 3 1,019 Jun-10-2019, 07:26 AM
Last Post: perfringo
  after using openpyxl to add colors to script, black shows up white online in excel Soundtechscott 1 745 Jun-08-2019, 10:33 PM
Last Post: Soundtechscott
  count unique values of a list with a list 3Pinter 2 2,402 Jul-05-2018, 11:52 AM
Last Post: 3Pinter
  Looping through dictionary and comparing values with elements of a separate list. Mr_Keystrokes 5 960 Jun-22-2018, 03:08 PM
Last Post: wavic
  Generating list of rsquared_adj regression values for variating i with loop hpg 1 1,211 Apr-18-2018, 07:33 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)