我无法保存参赛作品的颜色。这只是普通的账单

2024-10-05 14:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用cmap=sns.diversing_调色板设置我的表,输出良好,但我无法保存/导出它

我是如何创建它的(从这里开始Correlation heatmap

cmap = cmap=sns.diverging_palette(5, 250, as_cmap=True)

def magnify():
    return [dict(selector="th",
    props=[("font-size", "7pt")]),
    dict(selector="td",
    props=[('padding', "0em 0em")]),
    dict(selector="th:hover",
    props=[("font-size", "12pt")]),
    dict(selector="tr:hover td:hover",
    props=[('max-width', '200px'),
                    ('font-size', '12pt')])


cor.style.background_gradient(cmap='RdYlBu', axis=1)\
.set_properties(**{'max-width': '80px', 'font-size': '10pt'})\
.set_caption("Hover to magify")\
.set_precision(2)\
.set_table_styles(magnify())

  #and then 
  filename = 'correlation.html'
  f = open(filename,'w')
  wrapper = cor.style.render()
  f.write(wrapper)
  f.close()

html只显示原始文件,没有着色


Tags: sizepropswidthselectordictmaxtdcmap
1条回答
网友
1楼 · 发布于 2024-10-05 14:26:56

对于仍在搜索的人,我已经这样解决了:

cor.style.background_gradient(cmap = 'RdYlBu', axis=1)\ .set_properties(**{'max-width': '80px', 'font-size': '10pt'})\ .set_caption("Hover to magify")\ .set_precision(2)\ .set_table_styles(magnify()).to_excel('/path/file.xlsx', engine='openpyxl')

最后一部分不需要html,它保存为彩色excel

相关问题 更多 >