0

I tried with cmap=sns.diverging_palette to set my table and the output is good, but I can't save/export it.

how I created it (took it from here 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()

the html just shows the file like it is original, no colouring

cribb
  • 21
  • 3
  • `render()` outputs the html, but not the css for styling. I suppose the css is calculated at runtime and hence not included. – ImportanceOfBeingErnest Jan 28 '19 at 23:12
  • @ImportanceOfBeingErnest do you know how I can get the css for styling? Unfortunately I can't run the script every time I need to see the results because it takes too long and it also blocks safari – cribb Jan 29 '19 at 08:22
  • No, I don't know that. But consider that it might simply not be possible. Or else one could try to inspect the jupyter page's DOM to see if it's possible to extract the css out of it? – ImportanceOfBeingErnest Jan 29 '19 at 23:58

1 Answers1

0

for the people still searching, I've solved it like this:

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

no need for the last part with html and it is saved as a colourful excel

cribb
  • 21
  • 3