【发布时间】:2021-01-11 21:51:40
【问题描述】:
我有一个相似矩阵sim_matrix。我还有一个names 列表,每个列/行。可视化此矩阵的最简单方法是什么(即,低值,例如浅红色和高值深红色),用名称注释列和行?
我目前正在使用 xlsx_writer 执行此操作,但我确信使用 matplotlib 会更容易。
import xlsxwriter
workbook = xlsxwriter.Workbook('arrays.xlsx')
worksheet = workbook.add_worksheet()
f = lambda x, y: [f"{x} {no+1}" for no in range(y)] + [f"{x} mean"]
names = f("doc", len(urls))[:len(urls)] + f("wiki", len(wiki)) + f("para", len(paragraphs)) + f("topic", len(topics))
# Write name
for i, name in enumerate(names):
cell = i + 1
worksheet.write(cell, 0, name)
worksheet.write(0, cell, name)
# Write similarity values
for i, row in enumerate(sim_matrix):
for j, element in enumerate(row):
if j < i:
# Here I would have to differentiate and color accordingly. But that's really annoying
cell_format = workbook.add_format().set_bg_color("blue")
worksheet.write(i + 1, j + 1, element, cell_format)
workbook.close()
【问题讨论】:
-
是的,这正是我想要的。但我需要显示的数字+旁边的名字..
标签: python xlsxwriter