Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove lines separating cells in seaborn heatmap when saved as pdf

I would like to remove the lines that separate the cells in a saved pdf. I tried setting the linewidth=0.0, but the lines are still showing.

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

data = pd.DataFrame(np.arange(10*10).reshape(10,10))
fig, ax = plt.subplots()
ax = sns.heatmap(data,linewidths=0.0)
fig.savefig('stackoverflow_lines.pdf')

The image is a screen capture of the resulting pdf.

enter image description here

like image 993
Artturi Björk Avatar asked Nov 20 '14 13:11

Artturi Björk


People also ask

How do I remove a label from Seaborn heatmap?

To remove X or Y labels from a Seaborn heatmap, we can use yticklabel=False.

What is FMT in Seaborn heatmap?

The seaborn heatmap fmt help to show annot with different formatting.


1 Answers

This is an issue only when saving to PDF files, if you use something like a PNG then it will work fine. A Github Issue has been raised here with the developers.

In the meantime, the developer mwaskom has found a fix where you can add rasterized=True to the seaborn.heatmap function which fixes the issue. Your code then becomes:

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

data = pd.DataFrame(np.arange(10*10).reshape(10,10))
fig, ax = plt.subplots()
ax = sns.heatmap(data,linewidths=0.0, rasterized=True)
fig.savefig('stackoverflow_lines.pdf')
like image 132
Ffisegydd Avatar answered Nov 15 '22 19:11

Ffisegydd