Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Postscript backend gives wrong page sizes #16657

Copy link
Copy link
Closed
@griai

Description

@griai
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.