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

Skip to content

Commit 9f2a1f1

Browse files
committed
Merge pull request #4644 from ericmjl/mep12-text_rotation.py
MEP12 on text_rotation.py
2 parents 2c63e3d + 3600209 commit 9f2a1f1

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
"""
32
The way matplotlib does text layout is counter-intuitive to some, so
43
this example is designed to make it a little clearer. The text is
@@ -14,29 +13,32 @@
1413
1514
But a picture is worth a thousand words!
1615
"""
17-
from pylab import *
16+
17+
import matplotlib.pyplot as plt
18+
import numpy as np
1819

1920

2021
def addtext(props):
21-
text(0.5, 0.5, 'text 0', props, rotation=0)
22-
text(1.5, 0.5, 'text 45', props, rotation=45)
23-
text(2.5, 0.5, 'text 135', props, rotation=135)
24-
text(3.5, 0.5, 'text 225', props, rotation=225)
25-
text(4.5, 0.5, 'text -45', props, rotation=-45)
26-
yticks([0, .5, 1])
27-
grid(True)
22+
plt.text(0.5, 0.5, 'text 0', props, rotation=0)
23+
plt.text(1.5, 0.5, 'text 45', props, rotation=45)
24+
plt.text(2.5, 0.5, 'text 135', props, rotation=135)
25+
plt.text(3.5, 0.5, 'text 225', props, rotation=225)
26+
plt.text(4.5, 0.5, 'text -45', props, rotation=-45)
27+
plt.yticks([0, .5, 1])
28+
plt.grid(True)
2829

2930
# the text bounding box
3031
bbox = {'fc': '0.8', 'pad': 0}
3132

32-
subplot(211)
33+
plt.subplot(211)
3334
addtext({'ha': 'center', 'va': 'center', 'bbox': bbox})
34-
xlim(0, 5)
35-
xticks(arange(0, 5.1, 0.5), [])
36-
ylabel('center / center')
37-
subplot(212)
35+
plt.xlim(0, 5)
36+
plt.xticks(np.arange(0, 5.1, 0.5), [])
37+
plt.ylabel('center / center')
38+
39+
plt.subplot(212)
3840
addtext({'ha': 'left', 'va': 'bottom', 'bbox': bbox})
39-
xlim(0, 5)
40-
xticks(arange(0, 5.1, 0.5))
41-
ylabel('left / bottom')
42-
show()
41+
plt.xlim(0, 5)
42+
plt.xticks(np.arange(0, 5.1, 0.5))
43+
plt.ylabel('left / bottom')
44+
plt.show()

0 commit comments

Comments
 (0)