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

Skip to content

DOC: Cleanup spines usage in examples #24378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/sphinxext/gallery_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
5 changes: 1 addition & 4 deletions examples/showcase/integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([])

Expand Down
6 changes: 2 additions & 4 deletions examples/showcase/xkcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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'])
Expand Down
20 changes: 9 additions & 11 deletions examples/spines/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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`
37 changes: 0 additions & 37 deletions examples/spines/spines_bounds.py

This file was deleted.

9 changes: 2 additions & 7 deletions examples/spines/spines_dropped.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 0 additions & 2 deletions examples/statistics/customized_violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 1 addition & 3 deletions examples/ticks/tick-formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions examples/ticks/tick-locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down