Remove lines separating cells in seaborn heatmap when saved as pdf
heatmap, matplotlib, python, seaborn
Solution
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')
Problem
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.