Remove lines separating cells in nautical heatmap when saving as pdf
I would like to remove the rows that separate the cells in the saved pdf. I tried setting the line width = 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.
+3
source to share
1 answer
This is only an issue when saving to PDFs, if you use something like PNG then it will work fine. The Github issue was raised here with the developers.
In the meantime, the developer mwaskom has found a fix where you can add rasterized=True
in a function seaborn.heatmap
that fixes the problem. Then your code will look like this:
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')
+2
source to share