|
11 | 11 |
|
12 | 12 | Each `.axes.Axes` has a list of `.Spine` objects, accessible |
13 | 13 | via the container ``ax.spines``. |
| 14 | +
|
| 15 | +.. redirect-from:: /gallery/spines/spines_bounds |
| 16 | +
|
14 | 17 | """ |
15 | 18 | import numpy as np |
16 | 19 | import matplotlib.pyplot as plt |
|
31 | 34 | # Hide the right and top spines |
32 | 35 | ax1.spines.right.set_visible(False) |
33 | 36 | ax1.spines.top.set_visible(False) |
34 | | -# Only show ticks on the left and bottom spines |
35 | | -ax1.yaxis.set_ticks_position('left') |
36 | | -ax1.xaxis.set_ticks_position('bottom') |
37 | 37 |
|
38 | 38 | ax2.plot(x, y) |
| 39 | +ax2.set_title('spines with bounds limited to data range') |
39 | 40 |
|
40 | | -# Only draw spine between the y-ticks |
41 | | -ax2.spines.left.set_bounds(-1, 1) |
| 41 | +# Only draw spines for the data range, not in the margins |
| 42 | +ax2.spines.bottom.set_bounds(x.min(), x.max()) |
| 43 | +ax2.spines.left.set_bounds(y.min(), y.max()) |
42 | 44 | # Hide the right and top spines |
43 | 45 | ax2.spines.right.set_visible(False) |
44 | 46 | ax2.spines.top.set_visible(False) |
45 | | -# Only show ticks on the left and bottom spines |
46 | | -ax2.yaxis.set_ticks_position('left') |
47 | | -ax2.xaxis.set_ticks_position('bottom') |
48 | 47 |
|
49 | 48 | plt.show() |
50 | 49 |
|
|
53 | 52 | # The use of the following functions, methods, classes and modules is shown |
54 | 53 | # in this example: |
55 | 54 | # |
56 | | -# - `matplotlib.Spines.set_visible` |
57 | | -# - `matplotlib.Spines.set_bounds` |
58 | | -# - `matplotlib.axis.set_ticks_position` |
| 55 | +# - `matplotlib.spines.Spine.set_visible` |
| 56 | +# - `matplotlib.spines.Spine.set_bounds` |
0 commit comments