8000 Fix get_canvas_width_height() for pgf backend. · djdt/matplotlib@8713125 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8713125

Browse files
committed
Fix get_canvas_width_height() for pgf backend.
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.
1 parent d1941a7 commit 8713125

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The pgf backend's get_canvas_width_height now returns the canvas size in display units
2+
``````````````````````````````````````````````````````````````````````````````````````
3+
4+
... rather than in inches, which it previously did. The new behavior is the correct one given the uses of ``get_canvas_width_height`` in the rest of the codebase.

lib/matplotlib/backends/backend_pgf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ def flipy(self):
736736

737737
def get_canvas_width_height(self):
738738
# docstring inherited
739-
return self.figure.get_figwidth(), self.figure.get_figheight()
739+
return (self.figure.get_figwidth() * self.dpi,
740+
self.figure.get_figheight() * self.dpi)
740741

741742
def points_to_pixels(self, points):
742743
# docstring inherited

0 commit comments

Comments
 (0)
0