首页 > 解决方案 > 如何在 tkinter 画布 GUI 的一侧添加带有值的颜色条?

问题描述

我正在构建一个画布图像,其中每个圆的原点、半径和颜色都映射到数据框中的数据点,如下所示:

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()

这将在 tkinter 中创建以下画布绘图。如何将颜色栏添加到画布的一侧,颜色栏上有值?

在此处输入图像描述

标签: pythontkintertkinter-canvascolorbar

解决方案


推荐阅读