Skip to content

Commit bebe028

Browse files
committed
fix GH #17005
1 parent 800e810 commit bebe028

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

examples/text_labels_and_annotations/text_rotation_relative_to_line.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
to something on the plot. In this case, the correct angle won't be
1111
the angle of that object in the plot coordinate system, but the angle
1212
that that object APPEARS in the screen coordinate system. This angle
13-
is found by transforming the angle from the plot to the screen
14-
coordinate system, as shown in the example below.
13+
can be provided by the helper parameter `transform_rotates_text`, as
14+
shown in the example below.
1515
"""
1616

1717
import matplotlib.pyplot as plt
@@ -31,12 +31,12 @@
3131

3232
# Rotate angle
3333
angle = 45
34-
trans_angle = ax.transData.transform_angles([45], l2.reshape((1, 2)))[0]
3534

3635
# Plot text
3736
th1 = ax.text(*l1, 'text not rotated correctly', fontsize=16,
3837
rotation=angle, rotation_mode='anchor')
3938
th2 = ax.text(*l2, 'text rotated correctly', fontsize=16,
40-
rotation=trans_angle, rotation_mode='anchor')
39+
rotation=angle, rotation_mode='anchor',
40+
transform_rotates_text=True)
4141

4242
plt.show()

lib/matplotlib/tests/test_text.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import warnings
44

55
import numpy as np
6-
import pytest
76
from numpy.testing import assert_almost_equal
7+
import pytest
88

99
import matplotlib as mpl
1010
from matplotlib.backend_bases import MouseEvent
1111
import matplotlib.patches as mpatches
1212
import matplotlib.pyplot as plt
1313
import matplotlib.transforms as mtransforms
14-
from matplotlib.backend_bases import MouseEvent
1514
from matplotlib.testing.decorators import check_figures_equal, image_comparison
1615

1716
needs_usetex = pytest.mark.skipif(

0 commit comments

Comments
 (0)