我无法保存条目的颜色。这只是普通桌子

时间:2019-01-28 22:07:23

标签: python html dataframe render seaborn

我尝试使用cmap = sns.diverging_palette设置表,并且输出很好,但是我无法保存/导出它。

我是如何创建的(从这里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只是像原始文件一样显示文件,没有着色

1 个答案:

答案 0 :(得分:0)

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

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