0

I am constructing a canvas image where each circle's origin, radius and color are mapped to a data point from a dataframe, as follows:

data={'index': {0: 0, 1: 1, 2: 2, 3: 3},
 'ratio': {0: 726242000000,1: 56200692307, 2: 146376666666,3: 143607000000},
 'x': {0: 1228.7, 1: 1228.7, 2: 998.7, 3: 946.9},
 'y': {0: 1654.7, 1: 1326.7, 2: 1685.6,3: 2129},
 'dimension': {0: 35, 1: 35, 2: 35, 3: 35}}

image_factor=8
master=tkinter.Tk()
w=tkinter.Canvas(master,width=5000/image_factor, height=5000/image_factor)
minima = min(data.loc[:,'ratio'])
maxima = max(data.loc[:,'ratio'])
    
norm = matplotlib.colors.Normalize(vmin=minima, vmax=maxima, clip=True)
mapper = cm.ScalarMappable(norm=norm, cmap=cm.hsv)

for index, row in sample_summary.iterrows():
    w.create_circle((data.loc[index,'x'])/image_factor, (data.loc[index,'y'])/image_factor,data.loc[index,'dimension']/(2), fill=rgb2hex((mapper.to_rgba(data.loc[index,'ratio']))), outline=rgb2hex((mapper.to_rgba(data.loc[index,'ratio']))), width=1)

w.pack()
master.mainloop()

This creates the following canvas drawing in tkinter. How do I add a colorbar to the side of the canvas with values on the colorbar?

enter image description here

Harshad Surdi
  • 23
  • 1
  • 6

0 Answers0