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

Skip to content

Commit 49decb4

Browse files
authored
Merge pull request #14789 from anntzer/offset_transform
Prefer Affine2D.translate to offset_transform in examples.
2 parents 7e2dc93 + 6f6dc05 commit 49decb4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

examples/text_labels_and_annotations/rainbow_text.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
2121
Thanks.
2222
23-
Paul Ivanov responded with this answer:
24-
23+
The solution below is modified from Paul Ivanov's original answer.
2524
"""
25+
2626
import matplotlib.pyplot as plt
27-
from matplotlib import transforms
27+
from matplotlib.transforms import Affine2D
2828

2929

3030
def rainbow_text(x, y, strings, colors, orientation='horizontal',
@@ -64,11 +64,9 @@ def rainbow_text(x, y, strings, colors, orientation='horizontal',
6464
text.draw(canvas.get_renderer())
6565
ex = text.get_window_extent()
6666
if orientation == 'horizontal':
67-
t = transforms.offset_copy(
68-
text.get_transform(), x=ex.width, units='dots')
67+
t = text.get_transform() + Affine2D().translate(ex.width, 0)
6968
else:
70-
t = transforms.offset_copy(
71-
text.get_transform(), y=ex.height, units='dots')
69+
t = text.get_transform() + Affine2D().translate(0, ex.height)
7270

7371

7472
words = "all unicorns poop rainbows ! ! !".split()

0 commit comments

Comments
 (0)