|
1 |
| -#!/usr/bin/env python |
2 | 1 | """
|
3 | 2 | The way matplotlib does text layout is counter-intuitive to some, so
|
4 | 3 | this example is designed to make it a little clearer. The text is
|
|
14 | 13 |
|
15 | 14 | But a picture is worth a thousand words!
|
16 | 15 | """
|
17 |
| -from pylab import * |
| 16 | + |
| 17 | +import matplotlib.pyplot as plt |
| 18 | +import numpy as np |
18 | 19 |
|
19 | 20 |
|
20 | 21 | 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) |
28 | 29 |
|
29 | 30 | # the text bounding box
|
30 | 31 | bbox = {'fc': '0.8', 'pad': 0}
|
31 | 32 |
|
32 |
| -subplot(211) |
| 33 | +plt.subplot(211) |
33 | 34 | 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) |
38 | 40 | 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