Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33b3a82

Browse files
committed
DOC: Cleanup spines usage in examples
- hide spines using `set_visible(False)` instead of `set_color('none')` - remove `ax.xaxis.set_ticks_position('bottom')` and `ax.yaxis.set_ticks_position('left')`, because these are already the defaults - use multi-assignment (`spines[['left', 'bottom']].set_*`) when possible - Remove "Custom spine bounds" example. This is already included in the "Spines" example
1 parent 3d6c3da commit 33b3a82

File tree

9 files changed

+19
-71
lines changed

9 files changed

+19
-71
lines changed

doc/sphinxext/gallery_order.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def __call__(self, item):
7878
"eventplot", "hist2d", "hexbin", "pie",
7979
# Unstructured
8080
"tricontour", "tricontourf", "tripcolor", "triplot",
81+
# Spines
82+
"spines", "spine_placement_demo", "spines_dropped",
83+
"multiple_yaxis_with_spines", "centered_spines_with_arrows",
8184
]
8285
explicit_subsection_order = [item + ".py" for item in list_all]
8386

examples/showcase/integral.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ 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)
47-
ax.xaxis.set_ticks_position('bottom')
48-
45+
ax.spines[['top', 'right']].set_visible(False)
4946
ax.set_xticks([a, b], labels=['$a$', '$b$'])
5047
ax.set_yticks([])
5148

examples/showcase/xkcd.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
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[['top', 'right']].set_visible(False)
2120
ax.set_xticks([])
2221
ax.set_yticks([])
2322
ax.set_ylim([-30, 10])
@@ -47,8 +46,7 @@
4746
fig = plt.figure()
4847
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
4948
ax.bar([0, 1], [0, 100], 0.25)
50-
ax.spines.right.set_color('none')
51-
ax.spines.top.set_color('none')
49+
ax.spines[['top', 'right']].set_visible(False)
5250
ax.xaxis.set_ticks_position('bottom')
5351
ax.set_xticks([0, 1])
5452
ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])

examples/spines/spines.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
1212
Each `.axes.Axes` has a list of `.Spine` objects, accessible
1313
via the container ``ax.spines``.
14+
15+
.. redirect-from:: /gallery/spines/spines_bounds
16+
1417
"""
1518
import numpy as np
1619
import matplotlib.pyplot as plt
@@ -31,20 +34,16 @@
3134
# Hide the right and top spines
3235
ax1.spines.right.set_visible(False)
3336
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')
3737

3838
ax2.plot(x, y)
39+
ax2.set_title('spines with bounds limited to data range')
3940

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())
4244
# Hide the right and top spines
4345
ax2.spines.right.set_visible(False)
4446
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')
4847

4948
plt.show()
5049

@@ -53,6 +52,5 @@
5352
# The use of the following functions, methods, classes and modules is shown
5453
# in this example:
5554
#
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`

examples/spines/spines_bounds.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/spines/spines_dropped.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
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', 'bottom']].set_position(('outward', 10))
2322
# Hide the right and top spines
24-
ax.spines.right.set_visible(False)
25-
ax.spines.top.set_visible(False)
26-
# Only show ticks on the left and bottom spines
27-
ax.yaxis.set_ticks_position('left')
28-
ax.xaxis.set_ticks_position('bottom')
23+
ax.spines[['top', 'right']].set_visible(False)
2924

3025
plt.show()

examples/statistics/customized_violin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def adjacent_values(vals, q1, q3):
2727

2828

2929
def set_axis_style(ax, labels):
30-
ax.xaxis.set_tick_params(direction='out')
31-
ax.xaxis.set_ticks_position('bottom')
3230
ax.set_xticks(np.arange(1, len(labels) + 1), labels=labels)
3331
ax.set_xlim(0.25, len(labels) + 0.75)
3432
ax.set_xlabel('Sample name')

examples/ticks/tick-formatters.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ def setup(ax, title):
1818
"""Set up common parameters for the Axes in the example."""
1919
# only show the bottom spine
2020
ax.yaxis.set_major_locator(ticker.NullLocator())
21-
ax.spines.right.set_color('none')
22-
ax.spines.left.set_color('none')
23-
ax.spines.top.set_color('none')
21+
ax.spines[['left', 'right', 'top']].set_visible(False)
2422

2523
# define tick positions
2624
ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))

examples/ticks/tick-locators.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ 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[['left', 'right', 'top']].set_visible(False)
2321

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

0 commit comments

Comments
 (0)