|
1 | 1 | """ |
2 | | -Basic demo of axis spines. |
3 | | -
|
4 | | -This demo compares a normal axes, with spines on all four sides, and an axes |
5 | | -with spines only on the left and bottom. |
| 2 | +====== |
| 3 | +Spines |
| 4 | +====== |
| 5 | +
|
| 6 | +This demo compares: |
| 7 | + - normal axes, with spines on all four sides; |
| 8 | + - an axes with spines only on the left and bottom; |
| 9 | + - an axes using custom bounds to limit the extent of the spine. |
6 | 10 | """ |
7 | 11 | import numpy as np |
8 | 12 | import matplotlib.pyplot as plt |
|
11 | 15 | x = np.linspace(0, 2 * np.pi, 100) |
12 | 16 | y = 2 * np.sin(x) |
13 | 17 |
|
14 | | -fig, (ax0, ax1) = plt.subplots(nrows=2) |
| 18 | +fig, (ax0, ax1, ax2) = plt.subplots(nrows=3) |
15 | 19 |
|
16 | 20 | ax0.plot(x, y) |
17 | 21 | ax0.set_title('normal spines') |
|
26 | 30 | ax1.yaxis.set_ticks_position('left') |
27 | 31 | ax1.xaxis.set_ticks_position('bottom') |
28 | 32 |
|
| 33 | +ax2.plot(x, y) |
| 34 | + |
| 35 | +# Only draw spine between the y-ticks |
| 36 | +ax2.spines['left'].set_bounds(-1, 1) |
| 37 | +# Hide the right and top spines |
| 38 | +ax2.spines['right'].set_visible(False) |
| 39 | +ax2.spines['top'].set_visible(False) |
| 40 | +# Only show ticks on the left and bottom spines |
| 41 | +ax2.yaxis.set_ticks_position('left') |
| 42 | +ax2.xaxis.set_ticks_position('bottom') |
| 43 | + |
29 | 44 | # Tweak spacing between subplots to prevent labels from overlapping |
30 | 45 | plt.subplots_adjust(hspace=0.5) |
31 | | - |
32 | 46 | plt.show() |
0 commit comments