question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heatmap linewidths=0.0 not working when saving as PDF.

See original GitHub issue

A 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:closed
  • Created 9 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mwaskomcommented, Nov 21, 2014

OK figured it out, you need to pass rasterized=True to heatmap (which gets passed down to plt.pcolormesh).

0reactions
mwaskomcommented, Nov 22, 2014

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found