Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

SubplotBase._make_twin_axes always creates a new subplot instance #1972

Merged
merged 2 commits into from

3 participants

@mdboom
Owner

This is an alternative to #1969 that is based on v1.2.x and includes the test from #1957.

lib/matplotlib/tests/test_axes.py
@@ -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()
@pelson Collaborator
pelson added a note

Given how little detail is needed in the plot, I'm tempted to suggest reducing the PNG size with a combination of dpi and figsize. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mdboom
Owner

@pelson: Sure, I've shrunk the figure.

@mdboom mdboom merged commit 1909fef into from
@pelson
Collaborator

@pelson: Sure, I've shrunk the figure.

Thanks @mdboom. Good stuff :smile:

@mdboom mdboom deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2013
  1. @leejjoon @mdboom
  2. @mdboom

    Add a test for #1957

    mdboom authored
This page is out of date. Refresh to see the latest.
View
9 lib/matplotlib/axes.py
@@ -9062,7 +9062,14 @@ def _make_twin_axes(self, *kl, **kwargs):
"""
make a twinx axes of self. This is used for twinx and twiny.
"""
- ax2 = self.figure.add_subplot(self.get_subplotspec(), *kl, **kwargs)
+ from matplotlib.projections import process_projection_requirements
+ kl = (self.get_subplotspec(),) + kl
+ projection_class, kwargs, key = process_projection_requirements(
+ self.figure, *kl, **kwargs)
+
+ ax2 = subplot_class_factory(projection_class)(self.figure,
+ *kl, **kwargs)
+ self.figure.add_subplot(ax2)
return ax2
View
BIN  lib/matplotlib/tests/baseline_images/test_axes/twin_spines.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
47 lib/matplotlib/tests/test_axes.py
@@ -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(figsize=(4, 3))
+ 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)
Something went wrong with that request. Please try again.