Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List of colors
#1
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))]
Reply
#2
** 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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HOw define the colors for two columns? Jack_Sparrow 3 2,783 Jun-15-2018, 06:46 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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