Skip to content

Commit bdb9302

Browse files
committed
Use new Spines API throughout the library
1 parent 2b08562 commit bdb9302

File tree

26 files changed

+107
-121
lines changed

26 files changed

+107
-121
lines changed

examples/axes_grid1/demo_axes_rgb.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def demo_rgb2():
6060

6161
for ax in fig.axes:
6262
ax.tick_params(axis='both', direction='in')
63-
for sp1 in ax.spines.values():
64-
sp1.set_color("w")
63+
ax.spines.all.set_color("w")
6564
for tick in ax.xaxis.get_major_ticks() + ax.yaxis.get_major_ticks():
6665
tick.tick1line.set_markeredgecolor("w")
6766
tick.tick2line.set_markeredgecolor("w")

examples/images_contours_and_fields/image_annotated_heatmap.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ def heatmap(data, row_labels, col_labels, ax=None,
149149
rotation_mode="anchor")
150150

151151
# Turn spines off and create white grid.
152-
for edge, spine in ax.spines.items():
153-
spine.set_visible(False)
152+
ax.spines.all.set_visible(False)
154153

155154
ax.set_xticks(np.arange(data.shape[1]+1)-.5, minor=True)
156155
ax.set_yticks(np.arange(data.shape[0]+1)-.5, minor=True)

examples/lines_bars_and_markers/linestyles.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def plot_linestyles(ax, linestyles, title):
5454
yticks=np.arange(len(linestyles)),
5555
yticklabels=yticklabels)
5656
ax.tick_params(left=False, bottom=False, labelbottom=False)
57-
for spine in ax.spines.values():
58-
spine.set_visible(False)
57+
ax.spines.all.set_visible(False)
5958

6059
# For each line style, add a text annotation with a small offset from
6160
# the reference point (0 in Axes coords, y tick value in Data coords).

examples/showcase/bachelors_degrees_by_gender.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@
3232
'#17becf', '#9edae5'])
3333

3434
# Remove the plot frame lines. They are unnecessary here.
35-
ax.spines['top'].set_visible(False)
36-
ax.spines['bottom'].set_visible(False)
37-
ax.spines['right'].set_visible(False)
38-
ax.spines['left'].set_visible(False)
35+
ax.spines.all.set_visible(False)
3936

4037
# Ensure that the axis ticks only show up on the bottom and left of the plot.
4138
# Ticks on the right and top of the plot are generally unnecessary.

examples/showcase/integral.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def func(x):
4242
fig.text(0.9, 0.05, '$x$')
4343
fig.text(0.1, 0.9, '$y$')
4444

45-
ax.spines['right'].set_visible(False)
46-
ax.spines['top'].set_visible(False)
45+
ax.spines.right.set_visible(False)
46+
ax.spines.top.set_visible(False)
4747
ax.xaxis.set_ticks_position('bottom')
4848

4949
ax.set_xticks((a, b))

examples/showcase/xkcd.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
fig = plt.figure()
1818
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
19-
ax.spines['right'].set_color('none')
20-
ax.spines['top'].set_color('none')
19+
ax.spines.right.set_color('none')
20+
ax.spines.top.set_color('none')
2121
ax.set_xticks([])
2222
ax.set_yticks([])
2323
ax.set_ylim([-30, 10])
@@ -47,8 +47,8 @@
4747
fig = plt.figure()
4848
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
4949
ax.bar([0, 1], [0, 100], 0.25)
50-
ax.spines['right'].set_color('none')
51-
ax.spines['top'].set_color('none')
50+
ax.spines.right.set_color('none')
51+
ax.spines.top.set_color('none')
5252
ax.xaxis.set_ticks_position('bottom')
5353
ax.set_xticks([0, 1])
5454
ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])

examples/specialty_plots/skewt.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ class SkewXAxes(Axes):
8686
def _init_axis(self):
8787
# Taken from Axes and modified to use our modified X-axis
8888
self.xaxis = SkewXAxis(self)
89-
self.spines['top'].register_axis(self.xaxis)
90-
self.spines['bottom'].register_axis(self.xaxis)
89+
self.spines.top.register_axis(self.xaxis)
90+
self.spines.bottom.register_axis(self.xaxis)
9191
self.yaxis = maxis.YAxis(self)
92-
self.spines['left'].register_axis(self.yaxis)
93-
self.spines['right'].register_axis(self.yaxis)
92+
self.spines.left.register_axis(self.yaxis)
93+
self.spines.right.register_axis(self.yaxis)
9494

9595
def _gen_axes_spines(self):
9696
spines = {'top': SkewSpine.linear_spine(self, 'top'),

examples/subplots_axes_and_figures/broken_axis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
ax2.set_ylim(0, .22) # most of the data
3232

3333
# hide the spines between ax and ax2
34-
ax1.spines['bottom'].set_visible(False)
35-
ax2.spines['top'].set_visible(False)
34+
ax1.spines.bottom.set_visible(False)
35+
ax2.spines.top.set_visible(False)
3636
ax1.xaxis.tick_top()
3737
ax1.tick_params(labeltop=False) # don't put tick labels at the top
3838
ax2.xaxis.tick_bottom()

examples/ticks_and_spines/multiple_yaxis_with_spines.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
def make_patch_spines_invisible(ax):
1919
ax.set_frame_on(True)
2020
ax.patch.set_visible(False)
21-
for sp in ax.spines.values():
22-
sp.set_visible(False)
21+
ax.spines.all.set_visible(False)
2322

2423

2524
fig, host = plt.subplots()
@@ -30,13 +29,13 @@ def make_patch_spines_invisible(ax):
3029

3130
# Offset the right spine of par2. The ticks and label have already been
3231
# placed on the right by twinx above.
33-
par2.spines["right"].set_position(("axes", 1.2))
32+
par2.spines.right.set_position(("axes", 1.2))
3433
# Having been created by twinx, par2 has its frame off, so the line of its
3534
# detached spine is invisible. First, activate the frame but make the patch
3635
# and spines invisible.
3736
make_patch_spines_invisible(par2)
3837
# Second, show the right spine.
39-
par2.spines["right"].set_visible(True)
38+
par2.spines.right.set_visible(True)
4039

4140
p1, = host.plot([0, 1, 2], [0, 1, 2], "b-", label="Density")
4241
p2, = par1.plot([0, 1, 2], [0, 3, 2], "r-", label="Temperature")

examples/ticks_and_spines/spine_placement_demo.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,40 @@
1818
ax = fig.add_subplot(2, 2, 1)
1919
ax.set_title('centered spines')
2020
ax.plot(x, y)
21-
ax.spines['left'].set_position('center')
22-
ax.spines['right'].set_color('none')
23-
ax.spines['bottom'].set_position('center')
24-
ax.spines['top'].set_color('none')
21+
ax.spines.left.set_position('center')
22+
ax.spines.right.set_color('none')
23+
ax.spines.bottom.set_position('center')
24+
ax.spines.top.set_color('none')
2525
ax.xaxis.set_ticks_position('bottom')
2626
ax.yaxis.set_ticks_position('left')
2727

2828
ax = fig.add_subplot(2, 2, 2)
2929
ax.set_title('zeroed spines')
3030
ax.plot(x, y)
31-
ax.spines['left'].set_position('zero')
32-
ax.spines['right'].set_color('none')
33-
ax.spines['bottom'].set_position('zero')
34-
ax.spines['top'].set_color('none')
31+
ax.spines.left.set_position('zero')
32+
ax.spines.right.set_color('none')
33+
ax.spines.bottom.set_position('zero')
34+
ax.spines.top.set_color('none')
3535
ax.xaxis.set_ticks_position('bottom')
3636
ax.yaxis.set_ticks_position('left')
3737

3838
ax = fig.add_subplot(2, 2, 3)
3939
ax.set_title('spines at axes (0.6, 0.1)')
4040
ax.plot(x, y)
41-
ax.spines['left'].set_position(('axes', 0.6))
42-
ax.spines['right'].set_color('none')
43-
ax.spines['bottom'].set_position(('axes', 0.1))
44-
ax.spines['top'].set_color('none')
41+
ax.spines.left.set_position(('axes', 0.6))
42+
ax.spines.right.set_color('none')
43+
ax.spines.bottom.set_position(('axes', 0.1))
44+
ax.spines.top.set_color('none')
4545
ax.xaxis.set_ticks_position('bottom')
4646
ax.yaxis.set_ticks_position('left')
4747

4848
ax = fig.add_subplot(2, 2, 4)
4949
ax.set_title('spines at data (1, 2)')
5050
ax.plot(x, y)
51-
ax.spines['left'].set_position(('data', 1))
52-
ax.spines['right'].set_color('none')
53-
ax.spines['bottom'].set_position(('data', 2))
54-
ax.spines['top'].set_color('none')
51+
ax.spines.left.set_position(('data', 1))
52+
ax.spines.right.set_color('none')
53+
ax.spines.bottom.set_position(('data', 2))
54+
ax.spines.top.set_color('none')
5555
ax.xaxis.set_ticks_position('bottom')
5656
ax.yaxis.set_ticks_position('left')
5757

examples/ticks_and_spines/spines.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
ax1.set_title('bottom-left spines')
2727

2828
# Hide the right and top spines
29-
ax1.spines['right'].set_visible(False)
30-
ax1.spines['top'].set_visible(False)
29+
ax1.spines.right.set_visible(False)
30+
ax1.spines.top.set_visible(False)
3131
# Only show ticks on the left and bottom spines
3232
ax1.yaxis.set_ticks_position('left')
3333
ax1.xaxis.set_ticks_position('bottom')
3434

3535
ax2.plot(x, y)
3636

3737
# Only draw spine between the y-ticks
38-
ax2.spines['left'].set_bounds(-1, 1)
38+
ax2.spines.left.set_bounds(-1, 1)
3939
# Hide the right and top spines
40-
ax2.spines['right'].set_visible(False)
41-
ax2.spines['top'].set_visible(False)
40+
ax2.spines.right.set_visible(False)
41+
ax2.spines.top.set_visible(False)
4242
# Only show ticks on the left and bottom spines
4343
ax2.yaxis.set_ticks_position('left')
4444
ax2.xaxis.set_ticks_position('bottom')

examples/ticks_and_spines/spines_bounds.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
ax.set_yticks([-1, 0, 1])
2828

2929
# Only draw spine between the y-ticks
30-
ax.spines['left'].set_bounds((-1, 1))
30+
ax.spines.left.set_bounds((-1, 1))
3131
# Hide the right and top spines
32-
ax.spines['right'].set_visible(False)
33-
ax.spines['top'].set_visible(False)
32+
ax.spines.right.set_visible(False)
33+
ax.spines.top.set_visible(False)
3434
# Only show ticks on the left and bottom spines
3535
ax.yaxis.set_ticks_position('left')
3636
ax.xaxis.set_ticks_position('bottom')

examples/ticks_and_spines/spines_dropped.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
ax.set_title('dropped spines')
1919

2020
# Move left and bottom spines outward by 10 points
21-
ax.spines['left'].set_position(('outward', 10))
22-
ax.spines['bottom'].set_position(('outward', 10))
21+
ax.spines.left.set_position(('outward', 10))
22+
ax.spines.bottom.set_position(('outward', 10))
2323
# Hide the right and top spines
24-
ax.spines['right'].set_visible(False)
25-
ax.spines['top'].set_visible(False)
24+
ax.spines.right.set_visible(False)
25+
ax.spines.top.set_visible(False)
2626
# Only show ticks on the left and bottom spines
2727
ax.yaxis.set_ticks_position('left')
2828
ax.xaxis.set_ticks_position('bottom')

examples/ticks_and_spines/tick-formatters.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def setup(ax, title):
1717
"""Set up common parameters for the Axes in the example."""
1818
# only show the bottom spine
1919
ax.yaxis.set_major_locator(ticker.NullLocator())
20-
ax.spines['right'].set_color('none')
21-
ax.spines['left'].set_color('none')
22-
ax.spines['top'].set_color('none')
20+
ax.spines.right.set_color('none')
21+
ax.spines.left.set_color('none')
22+
ax.spines.top.set_color('none')
2323

2424
# define tick positions
2525
ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))

examples/ticks_and_spines/tick-locators.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def setup(ax, title):
1717
"""Set up common parameters for the Axes in the example."""
1818
# only show the bottom spine
1919
ax.yaxis.set_major_locator(ticker.NullLocator())
20-
ax.spines['right'].set_color('none')
21-
ax.spines['left'].set_color('none')
22-
ax.spines['top'].set_color('none')
20+
ax.spines.right.set_color('none')
21+
ax.spines.left.set_color('none')
22+
ax.spines.top.set_color('none')
2323

2424
ax.xaxis.set_ticks_position('bottom')
2525
ax.tick_params(which='major', width=1.00, length=5)

examples/userdemo/demo_gridspec06.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def squiggle_xy(a, b, c, d):
3030

3131
# show only the outside spines
3232
for ax in fig.get_axes():
33-
ax.spines['top'].set_visible(ax.is_first_row())
34-
ax.spines['bottom'].set_visible(ax.is_last_row())
35-
ax.spines['left'].set_visible(ax.is_first_col())
36-
ax.spines['right'].set_visible(ax.is_last_col())
33+
ax.spines.top.set_visible(ax.is_first_row())
34+
ax.spines.bottom.set_visible(ax.is_last_row())
35+
ax.spines.left.set_visible(ax.is_first_col())
36+
ax.spines.right.set_visible(ax.is_last_col())
3737

3838
plt.show()

lib/matplotlib/axes/_base.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,11 @@ def get_window_extent(self, *args, **kwargs):
613613
def _init_axis(self):
614614
# This is moved out of __init__ because non-separable axes don't use it
615615
self.xaxis = maxis.XAxis(self)
616-
self.spines['bottom'].register_axis(self.xaxis)
617-
self.spines['top'].register_axis(self.xaxis)
616+
self.spines.bottom.register_axis(self.xaxis)
617+
self.spines.top.register_axis(self.xaxis)
618618
self.yaxis = maxis.YAxis(self)
619-
self.spines['left'].register_axis(self.yaxis)
620-
self.spines['right'].register_axis(self.yaxis)
619+
self.spines.left.register_axis(self.yaxis)
620+
self.spines.right.register_axis(self.yaxis)
621621
self._update_transScale()
622622

623623
def set_figure(self, fig):
@@ -722,10 +722,10 @@ def get_xaxis_transform(self, which='grid'):
722722
return self._xaxis_transform
723723
elif which == 'tick1':
724724
# for cartesian projection, this is bottom spine
725-
return self.spines['bottom'].get_spine_transform()
725+
return self.spines.bottom.get_spine_transform()
726726
elif which == 'tick2':
727727
# for cartesian projection, this is top spine
728-
return self.spines['top'].get_spine_transform()
728+
return self.spines.top.get_spine_transform()
729729
else:
730730
raise ValueError('unknown value for which')
731731

@@ -798,10 +798,10 @@ def get_yaxis_transform(self, which='grid'):
798798
return self._yaxis_transform
799799
elif which == 'tick1':
800800
# for cartesian projection, this is bottom spine
801-
return self.spines['left'].get_spine_transform()
801+
return self.spines.left.get_spine_transform()
802802
elif which == 'tick2':
803803
# for cartesian projection, this is top spine
804-
return self.spines['right'].get_spine_transform()
804+
return self.spines.right.get_spine_transform()
805805
else:
806806
raise ValueError('unknown value for which')
807807

lib/matplotlib/axes/_secondary_axes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,13 @@ def set_color(self, color):
337337
"""
338338
if self._orientation == 'x':
339339
self.tick_params(axis='x', colors=color)
340-
self.spines['bottom'].set_color(color)
341-
self.spines['top'].set_color(color)
340+
self.spines.bottom.set_color(color)
341+
self.spines.top.set_color(color)
342342
self.xaxis.label.set_color(color)
343343
else:
344344
self.tick_params(axis='y', colors=color)
345-
self.spines['left'].set_color(color)
346-
self.spines['right'].set_color(color)
345+
self.spines.left.set_color(color)
346+
self.spines.right.set_color(color)
347347
self.yaxis.label.set_color(color)
348348

349349

lib/matplotlib/tests/test_axes.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -4324,8 +4324,7 @@ def test_twin_spines():
43244324
def make_patch_spines_invisible(ax):
43254325
ax.set_frame_on(True)
43264326
ax.patch.set_visible(False)
4327-
for sp in ax.spines.values():
4328-
sp.set_visible(False)
4327+
ax.spines.all.set_visible(False)
43294328

43304329
fig = plt.figure(figsize=(4, 3))
43314330
fig.subplots_adjust(right=0.75)
@@ -4336,13 +4335,13 @@ def make_patch_spines_invisible(ax):
43364335

43374336
# Offset the right spine of par2. The ticks and label have already been
43384337
# placed on the right by twinx above.
4339-
par2.spines["right"].set_position(("axes", 1.2))
4338+
par2.spines.right.set_position(("axes", 1.2))
43404339
# Having been created by twinx, par2 has its frame off, so the line of
43414340
# its detached spine is invisible. First, activate the frame but make
43424341
# the patch and spines invisible.
43434342
make_patch_spines_invisible(par2)
43444343
# Second, show the right spine.
4345-
par2.spines["right"].set_visible(True)
4344+
par2.spines.right.set_visible(True)
43464345

43474346
p1, = host.plot([0, 1, 2], [0, 1, 2], "b-")
43484347
p2, = par1.plot([0, 1, 2], [0, 3, 2], "r-")
@@ -5485,8 +5484,7 @@ def test_axisbelow():
54855484
ax.grid(color='c', linestyle='-', linewidth=3)
54865485
ax.tick_params(top=False, bottom=False,
54875486
left=False, right=False)
5488-
for spine in ax.spines.values():
5489-
spine.set_visible(False)
5487+
ax.spines.all.set_visible(False)
54905488
ax.set_axisbelow(setting)
54915489

54925490

@@ -5881,11 +5879,11 @@ def test_set_position():
58815879

58825880
def test_spines_properbbox_after_zoom():
58835881
fig, ax = plt.subplots()
5884-
bb = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
5882+
bb = ax.spines.bottom.get_window_extent(fig.canvas.get_renderer())
58855883
# this is what zoom calls:
58865884
ax._set_view_from_bbox((320, 320, 500, 500), 'in',
58875885
None, False, False)
5888-
bb2 = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
5886+
bb2 = ax.spines.bottom.get_window_extent(fig.canvas.get_renderer())
58895887
np.testing.assert_allclose(bb.get_points(), bb2.get_points(), rtol=1e-6)
58905888

58915889

@@ -6153,7 +6151,7 @@ def test_displaced_spine():
61536151
with rc_context({'_internal.classic_mode': False}):
61546152
fig, ax = plt.subplots(dpi=200, figsize=(6, 6))
61556153
ax.set(xticklabels=[], yticklabels=[])
6156-
ax.spines['bottom'].set_position(('axes', -0.1))
6154+
ax.spines.bottom.set_position(('axes', -0.1))
61576155
fig.canvas.draw()
61586156
bbaxis, bbspines, bbax, bbtb = color_boxes(fig, ax)
61596157

0 commit comments

Comments
 (0)