Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bbox_inches="tight" hardcoded #31

Open
tfiers opened this issue Sep 26, 2023 · 1 comment
Open

bbox_inches="tight" hardcoded #31

tfiers opened this issue Sep 26, 2023 · 1 comment

Comments

@tfiers
Copy link

tfiers commented Sep 26, 2023

All figures are displayed with matplotlib's auto-selection of the crop:

f.canvas.print_figure(io, format=$fmt, bbox_inches="tight")

This is a great default.
But sometimes you want to have more control over the bbox (especially when working with extreme aspect ratios, when "tight" produces totally different figsizes than what you requested).

Also, if in your rcparams, savefig.bbox is set to "standard" (the default) and not "tight", then your saved figures will differ from the displayed figures, which is confusing.

So, it would be nice if this hardcoded setting was somehow configureable in PythonPlot.

@tfiers
Copy link
Author

tfiers commented Sep 27, 2023

This is what I currently use to override PythonPlot's display
(ignoring other formats besides PNG, and foregoing the _showable(m, f) check):

using PythonPlot: Figure, matplotlib as mpl

function set_bbox(bbox = "standard")
    if bbox  ("standard", "tight")  # The dict-like `mpl.rcParams` object errors if not
        mpl.rcParams["savefig.bbox"] = bbox
    end
    # From PythonPlot.jl:
    @eval Main function Base.show(io::IO, m::MIME"image/png", f::Figure)
        if $(bbox == "standard")  # Can't pass that here.
            f.canvas.print_figure(io, format="png")
        else
            f.canvas.print_figure(io, format="png", bbox_inches=$bbox)
        end
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant