10000 Label outer offset text by anntzer · Pull Request #4446 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Label outer offset text #4446

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 2 commits into from
Mar 26, 2016
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: 2 additions & 1 deletion lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ def label_outer(self):
firstcol = self.is_first_col()
for label in self.get_xticklabels():
label.set_visible(lastrow)

self.get_xaxis().get_offset_text().set_visible(lastrow)
for label in self.get_yticklabels():
label.set_visible(firstcol)
self.get_yaxis().get_offset_text().set_visible(firstcol)

def _make_twin_axes(self, *kl, **kwargs):
"""
Expand Down
59 changes: 30 additions & 29 deletions lib/matplotlib/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,35 @@
from nose.tools import assert_raises


def check_shared(results, f, axs):
def check_shared(axs, x_shared, y_shared):
"""
results is a 4 x 4 x 2 matrix of boolean values where
if [i, j, 0] == True, X axis for subplots i and j should be shared
if [i, j, 1] == False, Y axis for subplots i and j should not be shared
x_shared and y_shared are n x n boolean matrices; entry (i, j) indicates
whether the x (or y) axes of subplots i and j should be shared.
"""
shared_str = ['x', 'y']
shared = [axs[0]._shared_x_axes, axs[0]._shared_y_axes]
#shared = {
# 'x': a1._shared_x_axes,
# 'y': a1._shared_y_axes,
# }
tostr = lambda r: "not " if r else ""
for i1 in xrange(len(axs)):
for i2 in xrange(i1 + 1, len(axs)):
for i3 in xrange(len(shared)):
assert shared[i3].joined(axs[i1], axs[i2]) == \
results[i1, i2, i3], \
"axes %i and %i incorrectly %ssharing %s axis" % \
(i1, i2, tostr(results[i1, i2, i3]), shared_str[i3])


def check_visible(result, f, axs):
for (i1, ax1), (i2, ax2), (i3, (name, shared)) in zip(
enumerate(axs),
enumerate(axs),
enumerate(zip("xy", [x_shared, y_shared]))):
if i2 <= i1:
continue
assert shared[i3].joined(ax1, ax2) == shared[i1, i2], \
"axes %i and %i incorrectly %ssharing %s axis" % (
i1, i2, "not " if shared[i1, i2] else "", name)


def check_visible(axs, x_visible, y_visible):
tostr = lambda v: "invisible" if v else "visible"
for (ax, vx, vy) in zip(axs, result['x'], result['y']):
for l in ax.get_xticklabels():
for (ax, vx, vy) in zip(axs, x_visible, y_visible):
for l in ax.get_xticklabels() + [ax.get_xaxis().offsetText]:
assert l.get_visible() == vx, \
"X axis was incorrectly %s" % (tostr(vx))
for l in ax.get_yticklabels():
for l in ax.get_yticklabels() + [ax.get_yaxis().offsetText]:
assert l.get_visible() == vy, \
"Y axis was incorrectly %s" % (tostr(vy))


@cleanup
def test_shared():
rdim = (4, 4, 2)
share = {
Expand Down Expand Up @@ -85,8 +81,7 @@ def test_shared():
# test default
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2)
axs = [a1, a2, a3, a4]
check_shared(numpy.dstack((share['none'], share['none'])), \
f, axs)
check_shared(axs, share['none'], share['none'])
plt.close(f)

# test all option combinations
Expand All @@ -95,12 +90,18 @@ def test_shared():
for yo in ops:
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2, sharex=xo, sharey=yo)
axs = [a1, a2, a3, a4]
check_shared(numpy.dstack((share[xo], share[yo])), \
f, axs)
check_visible(dict(x=visible['x'][xo], y=visible['y'][yo]), \
f, axs)
check_shared(axs, share[xo], share[yo])
check_visible(axs, visible['x'][xo], visible['y'][yo])
plt.close(f)

# test label_outer
f, ((a1, a2), (a3, a4)) = plt.subplots(2, 2, sharex=True, sharey=True)
axs = [a1, a2, a3, a4]
for ax in axs:
ax.label_outer()
check_visible(axs, [False, False, True, True], [True, False, True, False])



def test_exceptions():
# TODO should this test more options?
Expand Down
0