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

Skip to content

Fix get_canvas_width_height() for pgf backend. #14749

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

Merged
merged 1 commit into from
Jul 22, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 12, 2019

The pgf backend's get_canvas_width_height returns the canvas size in
inches, but it should return it in display units ("pixels", or
inches*dpi) instead.

get_canvas_width_height is actually barely used (only in text.py for
some backends (not pgf), in collections.py as an optimization, and in
BboxImage -- the only really relevant case), so to show the failure,
apply

diff --git i/examples/text_labels_and_annotations/demo_text_path.py w/examples/text_labels_and_annotations/demo_text_path.py
index 47ed5dde6..d45a922f4 100644
--- i/examples/text_labels_and_annotations/demo_text_path.py
+++ w/examples/text_labels_and_annotations/demo_text_path.py
@@ -61,6 +61,7 @@ class PathClippedImagePatch(mpatches.PathPatch):

if __name__ == "__main__":

+    import matplotlib; matplotlib.use("pgf")
    usetex = plt.rcParams["text.usetex"]

    fig = plt.figure()
@@ -156,4 +157,5 @@ if __name__ == "__main__":
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)

+    plt.savefig("/tmp/test.pdf")
    plt.show()

and observe that the image is incorrectly drawn before the patch, but
correctly after.

before:
old.pdf

after:
new.pdf

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug fix. Nevertheless, should we add an API changes note? Just in case somebody uses this and has adapted his code to the buggy return value.

The pgf backend's get_canvas_width_height returns the canvas size in
inches, but it should return it in display units ("pixels", or
inches*dpi) instead.

get_canvas_width_height is actually barely used (only in text.py for
some backends (not pgf), in collections.py as an optimization, and in
BboxImage -- the only really relevant case), so to show the failure,
apply

    diff --git i/examples/text_labels_and_annotations/demo_text_path.py w/examples/text_labels_and_annotations/demo_text_path.py
    index 47ed5dd..d45a922f4 100644
    --- i/examples/text_labels_and_annotations/demo_text_path.py
    +++ w/examples/text_labels_and_annotations/demo_text_path.py
    @@ -61,6 +61,7 @@ class PathClippedImagePatch(mpatches.PathPatch):

    if __name__ == "__main__":

    +    import matplotlib; matplotlib.use("pgf")
        usetex = plt.rcParams["text.usetex"]

        fig = plt.figure()
    @@ -156,4 +157,5 @@ if __name__ == "__main__":
        ax.set_xlim(0, 1)
        ax.set_ylim(0, 1)

    +    plt.savefig("/tmp/test.pdf")
        plt.show()

and observe that the image is incorrectly drawn before the patch, but
correctly after.
@anntzer
Copy link
Contributor Author

anntzer commented Jul 22, 2019

added api changes

@timhoffm timhoffm merged commit 4a5c939 into matplotlib:master Jul 22, 2019
@anntzer anntzer deleted the pgfwh branch July 22, 2019 22:12
@QuLogic QuLogic added this to the v3.2.0 milestone Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants