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

Skip to content

Commit 4bcb38f

Browse files
committed
PGF backend: support affine image transformations
1 parent 468a977 commit 4bcb38f

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,20 @@ def _pgf_path_draw(self, stroke=True, fill=False):
609609
actions.append("fill")
610610
writeln(self.fh, r"\pgfusepath{%s}" % ",".join(actions))
611611

612-
def draw_image(self, gc, x, y, im):
613-
# TODO: Almost no documentation for the behavior of this function.
614-
# Something missing?
612+
def option_scale_image(self):
613+
"""
614+
pgf backend supports affine transform of image.
615+
"""
616+
return True
617+
618+
def option_image_nocomposite(self):
619+
"""
620+
return whether to generate a composite image from multiple images on
621+
a set of axes
622+
"""
623+
return not rcParams['image.composite_image']
624+
625+
def draw_image(self, gc, x, y, im, transform=None):
615626
h, w = im.shape[:2]
616627
if w == 0 or h == 0:
617628
return
@@ -627,7 +638,22 @@ def draw_image(self, gc, x, y, im):
627638
writeln(self.fh, r"\begin{pgfscope}")
628639
self._print_pgf_clip(gc)
629640
f = 1. / self.dpi # from display coords to inch
630-
writeln(self.fh, r"\pgftext[at=\pgfqpoint{%fin}{%fin},left,bottom]{\pgfimage[interpolate=true,width=%fin,height=%fin]{%s}}" % (x * f, y * f, w * f, h * f, fname_img))
641+
if transform is None:
642+
writeln(self.fh,
643+
r"\pgfsys@transformshift{%fin}{%fin}" % (x * f, y * f))
644+
w, h = w * f, h * f
645+
else:
646+
tr1, tr2, tr3, tr4, tr5, tr6 = transform.frozen().to_values()
647+
writeln(self.fh,
648+
r"\pgfsys@transformcm{%f}{%f}{%f}{%f}{%fin}{%fin}" %
649+
(tr1 * f, tr2 * f, tr3 * f, tr4 * f,
650+
(tr5 + x) * f, (tr6 + y) * f))
651+
w = h = 1 # scale is already included in the transform
652+
interp = str(transform is None).lower() # interpolation in PDF reader
653+
writeln(self.fh,
654+
r"\pgftext[left,bottom]"
655+
r"{\pgfimage[interpolate=%s,width=%fin,height=%fin]{%s}}" %
656+
(interp, w, h, fname_img))
631657
writeln(self.fh, r"\end{pgfscope}")
632658

633659
def draw_tex(self, gc, x, y, s, prop, angle, ismath="TeX!", mtext=None):

0 commit comments

Comments
 (0)