Skip to content

Commit 6ddf5c0

Browse files
committed
Merge pull request matplotlib#2837 from tacaswell/spine_example_noclip
EXP : turn off clipping in spine example
2 parents 7563497 + 0550081 commit 6ddf5c0

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

examples/pylab_examples/spine_placement_demo.py

+31-30
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44

55
fig = plt.figure()
6-
x = np.linspace(-np.pi,np.pi,100)
6+
x = np.linspace(-np.pi, np.pi, 100)
77
y = 2*np.sin(x)
88

9-
ax = fig.add_subplot(2,2,1)
9+
ax = fig.add_subplot(2, 2, 1)
1010
ax.set_title('centered spines')
11-
ax.plot(x,y)
11+
ax.plot(x, y)
1212
ax.spines['left'].set_position('center')
1313
ax.spines['right'].set_color('none')
1414
ax.spines['bottom'].set_position('center')
@@ -18,9 +18,9 @@
1818
ax.xaxis.set_ticks_position('bottom')
1919
ax.yaxis.set_ticks_position('left')
2020

21-
ax = fig.add_subplot(2,2,2)
21+
ax = fig.add_subplot(2, 2, 2)
2222
ax.set_title('zeroed spines')
23-
ax.plot(x,y)
23+
ax.plot(x, y)
2424
ax.spines['left'].set_position('zero')
2525
ax.spines['right'].set_color('none')
2626
ax.spines['bottom'].set_position('zero')
@@ -30,38 +30,39 @@
3030
ax.xaxis.set_ticks_position('bottom')
3131
ax.yaxis.set_ticks_position('left')
3232

33-
ax = fig.add_subplot(2,2,3)
33+
ax = fig.add_subplot(2, 2, 3)
3434
ax.set_title('spines at axes (0.6, 0.1)')
35-
ax.plot(x,y)
36-
ax.spines['left'].set_position(('axes',0.6))
35+
ax.plot(x, y)
36+
ax.spines['left'].set_position(('axes', 0.6))
3737
ax.spines['right'].set_color('none')
38-
ax.spines['bottom'].set_position(('axes',0.1))
38+
ax.spines['bottom'].set_position(('axes', 0.1))
3939
ax.spines['top'].set_color('none')
4040
ax.spines['left'].set_smart_bounds(True)
4141
ax.spines['bottom'].set_smart_bounds(True)
4242
ax.xaxis.set_ticks_position('bottom')
4343
ax.yaxis.set_ticks_position('left')
4444

45-
ax = fig.add_subplot(2,2,4)
46-
ax.set_title('spines at data (1,2)')
47-
ax.plot(x,y)
48-
ax.spines['left'].set_position(('data',1))
45+
ax = fig.add_subplot(2, 2, 4)
46+
ax.set_title('spines at data (1, 2)')
47+
ax.plot(x, y)
48+
ax.spines['left'].set_position(('data', 1))
4949
ax.spines['right'].set_color('none')
50-
ax.spines['bottom'].set_position(('data',2))
50+
ax.spines['bottom'].set_position(('data', 2))
5151
ax.spines['top'].set_color('none')
5252
ax.spines['left'].set_smart_bounds(True)
5353
ax.spines['bottom'].set_smart_bounds(True)
5454
ax.xaxis.set_ticks_position('bottom')
5555
ax.yaxis.set_ticks_position('left')
5656
# ----------------------------------------------------
5757

58-
def adjust_spines(ax,spines):
58+
59+
def adjust_spines(ax, spines):
5960
for loc, spine in ax.spines.items():
6061
if loc in spines:
61-
spine.set_position(('outward',10)) # outward by 10 points
62+
spine.set_position(('outward', 10)) # outward by 10 points
6263
spine.set_smart_bounds(True)
6364
else:
64-
spine.set_color('none') # don't draw spine
65+
spine.set_color('none') # don't draw spine
6566

6667
# turn off ticks where there is no spine
6768
if 'left' in spines:
@@ -78,23 +79,23 @@ def adjust_spines(ax,spines):
7879

7980
fig = plt.figure()
8081

81-
x = np.linspace(0,2*np.pi,100)
82+
x = np.linspace(0, 2*np.pi, 100)
8283
y = 2*np.sin(x)
8384

84-
ax = fig.add_subplot(2,2,1)
85-
ax.plot(x,y)
86-
adjust_spines(ax,['left'])
85+
ax = fig.add_subplot(2, 2, 1)
86+
ax.plot(x, y, clip_on=False)
87+
adjust_spines(ax, ['left'])
8788

88-
ax = fig.add_subplot(2,2,2)
89-
ax.plot(x,y)
90-
adjust_spines(ax,[])
89+
ax = fig.add_subplot(2, 2, 2)
90+
ax.plot(x, y, clip_on=False)
91+
adjust_spines(ax, [])
9192

92-
ax = fig.add_subplot(2,2,3)
93-
ax.plot(x,y)
94-
adjust_spines(ax,['left','bottom'])
93+
ax = fig.add_subplot(2, 2, 3)
94+
ax.plot(x, y, clip_on=False)
95+
adjust_spines(ax, ['left', 'bottom'])
9596

96-
ax = fig.add_subplot(2,2,4)
97-
ax.plot(x,y)
98-
adjust_spines(ax,['bottom'])
97+
ax = fig.add_subplot(2, 2, 4)
98+
ax.plot(x, y, clip_on=False)
99+
adjust_spines(ax, ['bottom'])
99100

100101
plt.show()

0 commit comments

Comments
 (0)