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

Skip to content

Commit 12fa90e

Browse files
committed
Merge pull request #4643 from ericmjl/mep12-text_rotation_relative_to_line.py
MEP12 on text_rotation_relative_to_line.py
2 parents a3d4af0 + ee290b5 commit 12fa90e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

examples/pylab_examples/text_rotation_relative_to_line.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,29 @@
1010
is found by transforming the angle from the plot to the screen
1111
coordinate system, as shown in the example below.
1212
"""
13-
from pylab import *
13+
14+
import matplotlib.pyplot as plt
15+
import numpy as np
1416

1517
# Plot diagonal line (45 degrees)
16-
h = plot(r_[:10], r_[:10])
18+
h = plt.plot(np.arange(0, 10), np.arange(0, 10))
1719

1820
# set limits so that it no longer looks on screen to be 45 degrees
19-
xlim([-10, 20])
21+
plt.xlim([-10, 20])
2022

2123
# Locations to plot text
22-
l1 = array((1, 1))
23-
l2 = array((5, 5))
24+
l1 = np.array((1, 1))
25+
l2 = np.array((5, 5))
2426

2527
# Rotate angle
2628
angle = 45
27-
trans_angle = gca().transData.transform_angles(array((45,)),
29+
trans_angle = plt.gca().transData.transform_angles(np.array((45,)),
2830
l2.reshape((1, 2)))[0]
2931

3032
# Plot text
31-
th1 = text(l1[0], l1[1], 'text not rotated correctly', fontsize=16,
33+
th1 = plt.text(l1[0], l1[1], 'text not rotated correctly', fontsize=16,
3234
rotation=angle)
33-
th2 = text(l2[0], l2[1], 'text not rotated correctly', fontsize=16,
35+
th2 = plt.text(l2[0], l2[1], 'text not rotated correctly', fontsize=16,
3436
rotation=trans_angle)
3537

36-
show()
38+
plt.show()

0 commit comments

Comments
 (0)