Python Forum

Full Version: List of colors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to create to create a list of colors based on the labels contained in the array comms.

import matplotlib.pyplot as plt

cmap = plt.get_cmap("tab10")
ind = [10 if np.remainder(comms[i],10) == 0 else np.remainder(comms[i],10) for i in range(nx.number_of_nodes(G))]
I want to evaluate cmap at ind to obtain an array of colours.

How can I do that?

For some reason, the following returns a list of identical colours

colors = [cmap(10) if np.remainder(comms[i],10) == 0 else cmap(np.remainder(comms[i],10)) for i in range(nx.number_of_nodes(G))]
** Note ** Uses pythin 3.6 or newer change print statement for older versions of Python
You can use the built in color picker:
You'll have to work in your array:
import tkinter as tk
import tkinter.colorchooser as tkcolor

def color_picker():
    print(f'selected color: {tkcolor.askcolor()}')

def main():
    btn1 = tk.Button(text='Click Me', width=10, height=7, command=color_picker)
    btn1.pack(fill=tk.BOTH)
    tk.mainloop()

if __name__ == '__main__':
    main()