Skip to content

Commit f0a32b3

Browse files
committed
TST: add test for removing axes with shared axis
1 parent 0245db9 commit f0a32b3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,11 +4086,57 @@ def test_shared_scale():
40864086
assert_equal(ax.get_yscale(), 'linear')
40874087
assert_equal(ax.get_xscale(), 'linear')
40884088

4089+
40894090
@cleanup
40904091
def test_violin_point_mass():
40914092
"""Violin plot should handle point mass pdf gracefully."""
40924093
plt.violinplot(np.array([0, 0]))
40934094

4095+
4096+
@cleanup
4097+
def test_remove_shared_axes():
4098+
4099+
def _helper_x(ax):
4100+
ax2 = ax.twinx()
4101+
ax2.remove()
4102+
ax.set_xlim(0, 15)
4103+
r = ax.xaxis.get_major_locator()()
4104+
assert r[-1] > 14
4105+
4106+
def _helper_y(ax):
4107+
ax2 = ax.twiny()
4108+
ax2.remove()
4109+
ax.set_ylim(0, 15)
4110+
r = ax.yaxis.get_major_locator()()
4111+
assert r[-1] > 14
4112+
4113+
# test all of the ways to get fig/ax sets
4114+
fig = plt.figure()
4115+
ax = fig.gca()
4116+
yield _helper_x, ax
4117+
yield _helper_y, ax
4118+
4119+
fig, ax = plt.subplots()
4120+
yield _helper_x, ax
4121+
yield _helper_y, ax
4122+
4123+
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
4124+
ax = ax_lst[0][0]
4125+
yield _helper_x, ax
4126+
yield _helper_y, ax
4127+
4128+
fig = plt.figure()
4129+
ax = fig.add_axes([.1, .1, .8, .8])
4130+
yield _helper_x, ax
4131+
yield _helper_y, ax
4132+
4133+
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
4134+
ax = ax_lst[0][0]
4135+
orig_xlim = ax_lst[0][1].get_xlim()
4136+
ax.remove()
4137+
ax.set_xlim(0, 5)
4138+
assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)
4139+
40944140
if __name__ == '__main__':
40954141
import nose
40964142
import sys

0 commit comments

Comments
 (0)