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.
To remove X or Y labels from a Seaborn heatmap, we can use yticklabel=False.
The seaborn heatmap fmt help to show annot with different formatting.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With