首页 文章

保存为pdf时,删除将seaborn heatmap中的单元格分隔开的行

提问于
浏览
3

我想删除在保存的pdf中分隔单元格的行 . 我尝试设置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')

图像是生成的pdf的屏幕截图 .

enter image description here

1 回答

  • 2

    这只是在保存为PDF文件时才会出现问题,如果您使用类似PNG的内容,那么它将正常工作 . 与开发人员一起提出了Github问题here .

    与此同时,开发人员mwaskom找到了一个修复程序,你可以在 seaborn.heatmap 函数中添加 rasterized=True 来解决问题 . 然后你的代码变成:

    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')
    

相关问题