|
1 | 1 | """
|
2 | 2 | ===============
|
3 |
| -SpinePlacement |
| 3 | +Spineplacement |
4 | 4 | ===============
|
5 | 5 |
|
6 |
| -Adjustingthelocation and appearance of axis spines. |
| 6 | +The position oftheaxis spines can be influenced using `~.Spine.set_position`. |
7 | 7 |
|
8 | 8 | Note: If you want to obtain arrow heads at the ends of the axes, also check
|
9 | 9 | out the :doc:`/gallery/spines/centered_spines_with_arrows` example.
|
|
14 | 14 |
|
15 | 15 | ###############################################################################
|
16 | 16 |
|
17 |
| -fig=plt.figure() |
18 |
| -x=np.linspace(-np.pi,np.pi,100) |
| 17 | +x=np.linspace(0,2*np.pi,100) |
19 | 18 | y=2*np.sin(x)
|
20 | 19 |
|
21 |
| -ax=fig.add_subplot(2,2,1) |
22 |
| -ax.set_title('centered spines') |
| 20 | +fig,ax_dict=plt.subplot_mosaic( |
| 21 | + [['center','zero'], |
| 22 | + ['axes','data']] |
| 23 | +) |
| 24 | +fig.suptitle('Spine positions') |
| 25 | + |
| 26 | + |
| 27 | +ax=ax_dict['center'] |
| 28 | +ax.set_title("'center'") |
23 | 29 | ax.plot(x,y)
|
24 |
| -ax.spines.left.set_position('center') |
25 |
| -ax.spines.right.set_color('none') |
26 |
| -ax.spines.bottom.set_position('center') |
27 |
| -ax.spines.top.set_color('none') |
28 |
| -ax.xaxis.set_ticks_position('bottom') |
29 |
| -ax.yaxis.set_ticks_position('left') |
| 30 | +ax.spines[['left','bottom']].set_position('center') |
| 31 | +ax.spines[['top','right']].set_visible(False) |
30 | 32 |
|
31 |
| -ax=fig.add_subplot(2,2,2) |
32 |
| -ax.set_title('zeroed spines') |
| 33 | +ax=ax_dict['zero'] |
| 34 | +ax.set_title("'zero'") |
33 | 35 | ax.plot(x,y)
|
34 |
| -ax.spines.left.set_position('zero') |
35 |
| -ax.spines.right.set_color('none') |
36 |
| -ax.spines.bottom.set_position('zero') |
37 |
| -ax.spines.top.set_color('none') |
38 |
| -ax.xaxis.set_ticks_position('bottom') |
39 |
| -ax.yaxis.set_ticks_position('left') |
| 36 | +ax.spines[['left','bottom']].set_position('zero') |
| 37 | +ax.spines[['top','right']].set_visible(False) |
40 | 38 |
|
41 |
| -ax=fig.add_subplot(2,2,3) |
42 |
| -ax.set_title('spines ataxes (0.6, 0.1)') |
| 39 | +ax=ax_dict['axes'] |
| 40 | +ax.set_title("'axes' (0.2, 0.2)") |
43 | 41 | ax.plot(x,y)
|
44 |
| -ax.spines.left.set_position(('axes',0.6)) |
45 |
| -ax.spines.right.set_color('none') |
46 |
| -ax.spines.bottom.set_position(('axes',0.1)) |
47 |
| -ax.spines.top.set_color('none') |
48 |
| -ax.xaxis.set_ticks_position('bottom') |
49 |
| -ax.yaxis.set_ticks_position('left') |
| 42 | +ax.spines.left.set_position(('axes',0.2)) |
| 43 | +ax.spines.bottom.set_position(('axes',0.2)) |
| 44 | +ax.spines[['top','right']].set_visible(False) |
50 | 45 |
|
51 |
| -ax=fig.add_subplot(2,2,4) |
52 |
| -ax.set_title('spines atdata (1, 2)') |
| 46 | +ax=ax_dict['data'] |
| 47 | +ax.set_title("'data' (1, 2)") |
53 | 48 | ax.plot(x,y)
|
54 | 49 | ax.spines.left.set_position(('data',1))
|
55 |
| -ax.spines.right.set_color('none') |
56 | 50 | ax.spines.bottom.set_position(('data',2))
|
57 |
| -ax.spines.top.set_color('none') |
58 |
| -ax.xaxis.set_ticks_position('bottom') |
59 |
| -ax.yaxis.set_ticks_position('left') |
| 51 | +ax.spines[['top','right']].set_visible(False) |
60 | 52 |
|
61 | 53 | ###############################################################################
|
62 | 54 | # Define a method that adjusts the location of the axis spines
|
|