diff --git a/doc/sphinxext/gallery_order.py b/doc/sphinxext/gallery_order.py index 3632666d336e..e839d10360f9 100644 --- a/doc/sphinxext/gallery_order.py +++ b/doc/sphinxext/gallery_order.py @@ -78,6 +78,9 @@ def __call__(self, item): "eventplot", "hist2d", "hexbin", "pie", # Unstructured "tricontour", "tricontourf", "tripcolor", "triplot", + # Spines + "spines", "spine_placement_demo", "spines_dropped", + "multiple_yaxis_with_spines", "centered_spines_with_arrows", ] explicit_subsection_order = [item + ".py" for item in list_all] diff --git a/examples/showcase/integral.py b/examples/showcase/integral.py index c75ef940b0db..731f7b9ecd50 100644 --- a/examples/showcase/integral.py +++ b/examples/showcase/integral.py @@ -42,10 +42,7 @@ def func(x): fig.text(0.9, 0.05, '$x$') fig.text(0.1, 0.9, '$y$') -ax.spines.right.set_visible(False) -ax.spines.top.set_visible(False) -ax.xaxis.set_ticks_position('bottom') - +ax.spines[['top', 'right']].set_visible(False) ax.set_xticks([a, b], labels=['$a$', '$b$']) ax.set_yticks([]) diff --git a/examples/showcase/xkcd.py b/examples/showcase/xkcd.py index 4ab16c66a536..4088a0133814 100644 --- a/examples/showcase/xkcd.py +++ b/examples/showcase/xkcd.py @@ -16,8 +16,7 @@ fig = plt.figure() ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) - ax.spines.right.set_color('none') - ax.spines.top.set_color('none') + ax.spines[['top', 'right']].set_visible(False) ax.set_xticks([]) ax.set_yticks([]) ax.set_ylim([-30, 10]) @@ -47,8 +46,7 @@ fig = plt.figure() ax = fig.add_axes((0.1, 0.2, 0.8, 0.7)) ax.bar([0, 1], [0, 100], 0.25) - ax.spines.right.set_color('none') - ax.spines.top.set_color('none') + ax.spines[['top', 'right']].set_visible(False) ax.xaxis.set_ticks_position('bottom') ax.set_xticks([0, 1]) ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT']) diff --git a/examples/spines/spines.py b/examples/spines/spines.py index d21947d33636..0917fc8c107c 100644 --- a/examples/spines/spines.py +++ b/examples/spines/spines.py @@ -11,6 +11,9 @@ Each `.axes.Axes` has a list of `.Spine` objects, accessible via the container ``ax.spines``. + +.. redirect-from:: /gallery/spines/spines_bounds + """ import numpy as np import matplotlib.pyplot as plt @@ -31,20 +34,16 @@ # Hide the right and top spines ax1.spines.right.set_visible(False) ax1.spines.top.set_visible(False) -# Only show ticks on the left and bottom spines -ax1.yaxis.set_ticks_position('left') -ax1.xaxis.set_ticks_position('bottom') ax2.plot(x, y) +ax2.set_title('spines with bounds limited to data range') -# Only draw spine between the y-ticks -ax2.spines.left.set_bounds(-1, 1) +# Only draw spines for the data range, not in the margins +ax2.spines.bottom.set_bounds(x.min(), x.max()) +ax2.spines.left.set_bounds(y.min(), y.max()) # Hide the right and top spines ax2.spines.right.set_visible(False) ax2.spines.top.set_visible(False) -# Only show ticks on the left and bottom spines -ax2.yaxis.set_ticks_position('left') -ax2.xaxis.set_ticks_position('bottom') plt.show() @@ -53,6 +52,5 @@ # The use of the following functions, methods, classes and modules is shown # in this example: # -# - `matplotlib.Spines.set_visible` -# - `matplotlib.Spines.set_bounds` -# - `matplotlib.axis.set_ticks_position` +# - `matplotlib.spines.Spine.set_visible` +# - `matplotlib.spines.Spine.set_bounds` diff --git a/examples/spines/spines_bounds.py b/examples/spines/spines_bounds.py deleted file mode 100644 index 5ccf3051e1ea..000000000000 --- a/examples/spines/spines_bounds.py +++ /dev/null @@ -1,37 +0,0 @@ -""" -=================== -Custom spine bounds -=================== - -Demo of spines using custom bounds to limit the extent of the spine. -""" -import numpy as np -import matplotlib.pyplot as plt - -# Fixing random state for reproducibility -np.random.seed(19680801) - -x = np.linspace(0, 2*np.pi, 50) -y = np.sin(x) -y2 = y + 0.1 * np.random.normal(size=x.shape) - -fig, ax = plt.subplots() -ax.plot(x, y) -ax.plot(x, y2) - -# set ticks and tick labels -ax.set_xlim((0, 2*np.pi)) -ax.set_xticks([0, np.pi, 2*np.pi], labels=['0', r'$\pi$', r'2$\pi$']) -ax.set_ylim((-1.5, 1.5)) -ax.set_yticks([-1, 0, 1]) - -# Only draw spine between the y-ticks -ax.spines.left.set_bounds((-1, 1)) -# Hide the right and top spines -ax.spines.right.set_visible(False) -ax.spines.top.set_visible(False) -# Only show ticks on the left and bottom spines -ax.yaxis.set_ticks_position('left') -ax.xaxis.set_ticks_position('bottom') - -plt.show() diff --git a/examples/spines/spines_dropped.py b/examples/spines/spines_dropped.py index 954e1c7ffb3a..94487e86d1d3 100644 --- a/examples/spines/spines_dropped.py +++ b/examples/spines/spines_dropped.py @@ -18,13 +18,8 @@ ax.set_title('dropped spines') # Move left and bottom spines outward by 10 points -ax.spines.left.set_position(('outward', 10)) -ax.spines.bottom.set_position(('outward', 10)) +ax.spines[['left', 'bottom']].set_position(('outward', 10)) # Hide the right and top spines -ax.spines.right.set_visible(False) -ax.spines.top.set_visible(False) -# Only show ticks on the left and bottom spines -ax.yaxis.set_ticks_position('left') -ax.xaxis.set_ticks_position('bottom') +ax.spines[['top', 'right']].set_visible(False) plt.show() diff --git a/examples/statistics/customized_violin.py b/examples/statistics/customized_violin.py index 4809e5f28d81..59978815e57e 100644 --- a/examples/statistics/customized_violin.py +++ b/examples/statistics/customized_violin.py @@ -27,8 +27,6 @@ def adjacent_values(vals, q1, q3): def set_axis_style(ax, labels): - ax.xaxis.set_tick_params(direction='out') - ax.xaxis.set_ticks_position('bottom') ax.set_xticks(np.arange(1, len(labels) + 1), labels=labels) ax.set_xlim(0.25, len(labels) + 0.75) ax.set_xlabel('Sample name') diff --git a/examples/ticks/tick-formatters.py b/examples/ticks/tick-formatters.py index ac118cbfce03..0f5c8f38d411 100644 --- a/examples/ticks/tick-formatters.py +++ b/examples/ticks/tick-formatters.py @@ -18,9 +18,7 @@ def setup(ax, title): """Set up common parameters for the Axes in the example.""" # only show the bottom spine ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.spines.right.set_color('none') - ax.spines.left.set_color('none') - ax.spines.top.set_color('none') + ax.spines[['left', 'right', 'top']].set_visible(False) # define tick positions ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) diff --git a/examples/ticks/tick-locators.py b/examples/ticks/tick-locators.py index eeac29a07ad2..1832f382529e 100644 --- a/examples/ticks/tick-locators.py +++ b/examples/ticks/tick-locators.py @@ -17,9 +17,7 @@ def setup(ax, title): """Set up common parameters for the Axes in the example.""" # only show the bottom spine ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.spines.right.set_color('none') - ax.spines.left.set_color('none') - ax.spines.top.set_color('none') + ax.spines[['left', 'right', 'top']].set_visible(False) ax.xaxis.set_ticks_position('bottom') ax.tick_params(which='major', width=1.00, length=5)