[英]Remove lines separating cells in seaborn heatmap when saved as pdf
I would like to remove the lines that separate the cells in a saved pdf. 我想删除在保存的pdf中分隔单元格的行。 I tried setting the linewidth=0.0, but the lines are still showing.
我尝试设置linewidth = 0.0,但线条仍在显示。
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. 图像是生成的pdf的屏幕截图。
This is an issue only when saving to PDF files, if you use something like a PNG then it will work fine. 这只是在保存为PDF文件时才会出现问题,如果您使用类似PNG的内容,那么它将正常工作。 A Github Issue has been raised here with the developers.
这里与开发人员一起提出了 Github问题。
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. 与此同时,开发人员mwaskom找到了一个修复程序,您可以在其中将
rasterized=True
添加到修复问题的seaborn.heatmap
函数中。 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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.