python - 如何在 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 中创建以下画布绘图。如何将颜色栏添加到画布的一侧,颜色栏上有值?
解决方案
推荐阅读
- r - 按最大日期划分的重复值的子集数据框
- database - 第一次在 python 中对大型 SQLite DB 执行查询需要很长时间
- swift - Couchbase 接收 Channel null
- spring-boot - Spring Boot 缓存批量和单独访问
- c# - 确定表中的多个布尔列对于记录是否为真
- dialogflow-es - 如何在 Dialogflow 中获取用户 ID 和 OAuth 访问令牌
- javascript - 为什么将componentDidMount更改为非箭头函数会使热重载再次起作用?
- typescript - Typescript中每个文件的显式全局变量
- scala - 使用 OFormat 序列化案例类时从播放应用程序收到警告
- javascript - 单击提交后附加表单数据