Heatmap linewidths=0.0 not working when saving as PDF.
See original GitHub issueA question on Stack Overflow was recently asked here where using sns.heatmap(data,linewidths=0.0)
and saving the plot as a PDF doesn’t seem to work as there is still a gap between each “cell”.
The code below is from the question (in case the question is deleted, etc) and reproduces the issue
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_pdf.pdf')
If a PNG is used then it seems to work fine, i.e. the linewidth is zero and there are no gaps in between cells.
System details:
- Python 3.4.2
- matplotlib 1.4.2
- seaborn 0.5.0
Edited: had the wrong SO question link --_
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Remove lines separating cells in seaborn heatmap when ...
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...
Read more >Seaborn Heatmap using sns.heatmap() - Indian AI Production
Python seaborn heatmap is a graphical representation of 2D data. Each data value represents in a matrix and it has a special color...
Read more >Creating annotated heatmaps — Matplotlib 3.6.2 documentation
Creating annotated heatmaps#. It is often desirable to show data which depends on two independent variables as a color coded image plot.
Read more >Lesson5: Visualizing clusters with heatmap and dendrogram
Introduce the heatmap and dendrogram as tools for visualizing clusters in data. Learn to construct cluster heatmap using the package pheatmap . Learn...
Read more >Chapter 4. Visualization with Matplotlib - O'Reilly
IPython is built to work well with Matplotlib if you specify Matplotlib mode. ... Note that when saving your figure, it's not necessary...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK figured it out, you need to pass
rasterized=True
toheatmap
(which gets passed down toplt.pcolormesh
).Gonna close this as there’s really nothing seaborn could do to avoid these lines. See here for a bit more info about why this is an issue with the pdf rendering, and not the drawing per se.