Exemple #1
0
def _get_tight_size(max_figure: Figure, title: str):
    """get cropped size for max_figure after adding optional title"""
    # first, place suptitle close to axes
    if title:
        tight_bbox = max_figure.get_tightbbox(max_figure.canvas.get_renderer())
        y_rel = tight_bbox.ymax / max_figure.bbox_inches.ymax
        max_figure.suptitle(title, y=y_rel + 0.02, verticalalignment="bottom")

    max_figure.tight_layout()
    tight_bbox = max_figure.get_tightbbox(max_figure.canvas.get_renderer())
    max_figure_size = max_figure.bbox_inches.size

    # only crop in one direction
    if tight_bbox.size[0] / max_figure_size[0] < tight_bbox.size[
            1] / max_figure_size[1]:
        return tight_bbox.size[0], max_figure_size[1]
    else:
        return max_figure_size[0], tight_bbox.size[1]