【问题标题】:Add dpi to seaborn or export them with a given dpi将 dpi 添加到 seaborn 或使用给定的 dpi 导出它们
【发布时间】:2019-11-08 14:32:01
【问题描述】:

我有如下可视化代码:

for cluster in ready_couples_2.cluster.unique():
    sns.set(rc={'figure.figsize':(11.7,8.27)})
    # mask the cluster of interest
    is_cluster = ready_couples_2.cluster.eq(cluster)

    ax = ready_couples_2[~is_cluster].plot.scatter(x='longitude',y='latitude', c='gray') 

    ax = sns.scatterplot(data=ready_couples_2[is_cluster],
                    x='longitude', 
                    y='latitude',
                    hue='id_easy',
                    ax=ax)
    ax.legend_.remove()

    figure = ax.get_figure()    
    figure.savefig('test.png', dpi=500)

    plt.show()

但是figure 只保存了给定地块中的一个地块。如何将它们全部保存或如何在绘图时定义 DPI?

【问题讨论】:

    标签: python matplotlib seaborn dpi


    【解决方案1】:

    嗯,它确实保存了您所有的图形,但是因为您没有更改文件名,所以最后一个图将是您看到的唯一一个。

    例如你可以这样做

    for ind, cluster in enumerate(ready_couples_2.cluster.unique()):
        ...
        figure.savefig('test%d.png' % ind, dpi=500)
    

    【讨论】:

      猜你喜欢
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多