Skip to content

Commit

Permalink
Add a test for matplotlib#1957
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed May 3, 2013
1 parent 377facb commit 6df3f33
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -1090,3 +1090,50 @@ def test_mixed_collection():

ax.set_xlim(0, 16)
ax.set_ylim(0, 16)


@image_comparison(baseline_images=['twin_spines'], remove_text=True,
extensions=['png'])
def test_twin_spines():

def make_patch_spines_invisible(ax):
ax.set_frame_on(True)
ax.patch.set_visible(False)
for sp in ax.spines.itervalues():
sp.set_visible(False)

fig = plt.figure()
fig.subplots_adjust(right=0.75)

host = fig.add_subplot(111)
par1 = host.twinx()
par2 = host.twinx()

# Offset the right spine of par2. The ticks and label have already been
# placed on the right by twinx above.
par2.spines["right"].set_position(("axes", 1.2))
# Having been created by twinx, par2 has its frame off, so the line of its
# detached spine is invisible. First, activate the frame but make the patch
# and spines invisible.
make_patch_spines_invisible(par2)
# Second, show the right spine.
par2.spines["right"].set_visible(True)

p1, = host.plot([0, 1, 2], [0, 1, 2], "b-")
p2, = par1.plot([0, 1, 2], [0, 3, 2], "r-")
p3, = par2.plot([0, 1, 2], [50, 30, 15], "g-")

host.set_xlim(0, 2)
host.set_ylim(0, 2)
par1.set_ylim(0, 4)
par2.set_ylim(1, 65)

host.yaxis.label.set_color(p1.get_color())
par1.yaxis.label.set_color(p2.get_color())
par2.yaxis.label.set_color(p3.get_color())

tkw = dict(size=4, width=1.5)
host.tick_params(axis='y', colors=p1.get_color(), **tkw)
par1.tick_params(axis='y', colors=p2.get_color(), **tkw)
par2.tick_params(axis='y', colors=p3.get_color(), **tkw)
host.tick_params(axis='x', **tkw)

0 comments on commit 6df3f33

Please sign in to comment.