首页 > 解决方案 > matplotlib .ps 输出被截断

问题描述

我正在绘制一个matplotlib.subplots使用plt.savefig() 所有其他格式生成正确输出的图。只有当我将其保存为 .ps 文件时,才会生成截断图。我试过 set plt.tight_layout() 但它不起作用。

样本

这是一个例子:

import numpy as np
import matplotlib.pyplot as plt

v_x = np.random.randint(0, 80000, 30000)
v_y = v_x # the x, y cordinate of the dots.

f,axes = plt.subplots(5,5,figsize = (40,40))
for row in range(5):
    for col in range(5):
        print(row,col)

        axes[row,col].set_yticklabels([])
        axes[row,col].set_xticklabels([])

        if row > col:
            axes[row,col].axis('off')
        else:
            axes[row,col].set_xlim(0,len(v_x))
            axes[row,col].set_ylim(0,len(v_y))


            axes[row,col].scatter(v_x,v_y, c = '#000000', s=(72./300)**2, marker = 's', edgecolor= '')
f.savefig('{}'.format('test.ps'), facecolor='w', bbox_inches='tight', dpi = 300)

标签: pythonmatplotlib

解决方案


尝试摆脱

figsize = (40, 40)

看起来您的身材被 figsize 参数截断了。


推荐阅读