![]() |
How do I map a list of values to specified colors? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How do I map a list of values to specified colors? (/thread-22212.html) |
How do I map a list of values to specified colors? - larkypython - Nov-04-2019 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. RE: How do I map a list of values to specified colors? - Larz60+ - Nov-04-2019 what have you tried? RE: How do I map a list of values to specified colors? - larkypython - Nov-05-2019 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! RE: How do I map a list of values to specified colors? - MckJohan - Nov-05-2019 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]) RE: How do I map a list of values to specified colors? - larkypython - Nov-05-2019 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 |