Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Postscript backend gives wrong page sizes #16657

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

Closed
griai opened this issue Mar 4, 2020 · 4 comments · Fixed by #26479
Closed

Postscript backend gives wrong page sizes #16657

griai opened this issue Mar 4, 2020 · 4 comments · Fixed by #26479

Comments

@griai
Copy link

griai commented Mar 4, 2020

Bug report

Bug summary

When creating a Figure of exactly A4 size, the PS backend chooses "letter" as document type, leading to additional borders of the output in x direction and undesired cropping in y direction.

Code for reproduction

import matplotlib as mpl
mpl.use("PS")

import matplotlib.pyplot as plt


# Use "exact" A4 paper size in inches as used in PS backend.

# In fact, it is wrong, because it is rounded to only two digits,
# where actually the ISO standardized values (ISO 216) are given
# in millimeters.

A4_SIZE_IN = (8.27, 11.69)

def get_empty_page(figsize):
    fig, ax = plt.subplots(
        subplot_kw={
            "position": (0, 0, 1, 1),
            "autoscale_on": False,
            "xmargin": 0,
            "ymargin": 0,
        },
        figsize=figsize
    )
    fig.dpi = 72
    ax.tick_params(direction="in")
    ax.set_axis_off()  # turns off ticks, labels, frame, grid
    return fig, ax

fig, ax = get_empty_page(figsize=A4_SIZE_IN)

# Put blue circles exactly in the corners of the figure.
# They shall appear as quarter circles in the output.
ax.plot([0, 1], [1, 0], "bo", ms=100)

fig.savefig("size_wo_papertype.ps")
fig.savefig("size_w_papertype.ps", papertype="a4")

Actual outcome

When not specifying the papertype explicitly, the PS backend chooses "letter" format as can be seen from the resulting postscript output. It should, instead, choose A4 format. When specifying the papertype explicitly, the output looks fine.

Expected outcome

The PS backend should choose A4 format if the Figure is exactly this size. Anyway, nothing should ever be cropped off the Figure. If the Figure does not fit one papertype, the next larger one should be chosen.
I also do not understand why the output of the PS backend is restricted to a handfull of explicit paper sizes in the first place. Postscript does well support arbitrary page sizes. Can someone explain why matplotlib chose to only support the given sizes? This is not transparent to the user, who expects to get output of exactly the size of his/her desired Figure object.

Matplotlib version

  • Operating system: Ubuntu 19.04
  • Matplotlib version: 3.1.1
  • Matplotlib backend: PS
  • Python version: 3.7.4
  • Jupyter version: 1.0.0
  • Other libraries:

Matplotlib was installed via conda.

@anntzer
Copy link
Contributor

anntzer commented Mar 4, 2020

This appears to have been added in 8b01579 without explaining why (before that commit, ps simply did not set the DocumentPaperSize entry).
I agree there's no particular reason to restrict postscript output to a fixed number of sizes; conversely other output formats (in particular, pdf) may benefit from this kind of sizing-to-papersize. So as always, the main remaining question is what would be a better API and how do we do the transition...

@griai
Copy link
Author

griai commented Mar 4, 2020

Thanks, @anntzer for your thoughts on this! In my opinion, the default output size should be Figure.size in all cases. This is also what the user knows from other backends.
Whether or not there is the additional option to provide different predefined output sizes (for example for printing on paper) is, indeed, a different question.

@anntzer
Copy link
Contributor

anntzer commented Mar 4, 2020

I agree with you.
One possible way forward (for example) may be (I haven't ironed out the details) to extend rcParams["savefig.bbox"] (currently just "bbox" or "standard") to also support other papersizes (either a name ("A4", etc.) or a pair of floats (width, height)), and likewise for the bbox_inches kwarg to savefig(), and deprecate rcParams["ps.papersize"].

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jul 12, 2023
@QuLogic QuLogic added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Aug 2, 2023
@QuLogic QuLogic added this to the v3.8.0 milestone Aug 9, 2023
@QuLogic QuLogic removed the keep Items to be ignored by the “Stale” Github Action label Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants