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

Skip to content

Commit 95cfcae

Browse files
committed
Merge pull request #2472 from mdboom/twin-spines-on-top
Plots using twinx draw on top of figure frame
2 parents 30e37eb + 6103f64 commit 95cfcae

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

lib/matplotlib/axes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8036,13 +8036,13 @@ def twinx(self):
80368036
For those who are 'picking' artists while using twinx, pick
80378037
events are only called for the artists in the top-most axes.
80388038
"""
8039-
8040-
ax2 = self._make_twin_axes(sharex=self, frameon=False)
8039+
ax2 = self._make_twin_axes(sharex=self)
80418040
ax2.yaxis.tick_right()
80428041
ax2.yaxis.set_label_position('right')
80438042
ax2.yaxis.set_offset_position('right')
80448043
self.yaxis.tick_left()
80458044
ax2.xaxis.set_visible(False)
8045+
ax2.patch.set_visible(False)
80468046
return ax2
80478047

80488048
def twiny(self):
@@ -8061,11 +8061,12 @@ def twiny(self):
80618061
events are only called for the artists in the top-most axes.
80628062
"""
80638063

8064-
ax2 = self._make_twin_axes(sharey=self, frameon=False)
8064+
ax2 = self._make_twin_axes(sharey=self)
80658065
ax2.xaxis.tick_top()
80668066
ax2.xaxis.set_label_position('top')
80678067
self.xaxis.tick_bottom()
80688068
ax2.yaxis.set_visible(False)
8069+
ax2.patch.set_visible(False)
80698070
return ax2
80708071

80718072
def get_shared_x_axes(self):

lib/matplotlib/tests/test_axes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,27 @@ def make_patch_spines_invisible(ax):
16461646
host.tick_params(axis='x', **tkw)
16471647

16481648

1649+
@image_comparison(baseline_images=['twin_spines_on_top'], extensions=['png'],
1650+
remove_text=True)
1651+
def test_twin_spines_on_top():
1652+
matplotlib.rcParams['axes.linewidth'] = 48.0
1653+
matplotlib.rcParams['lines.linewidth'] = 48.0
1654+
1655+
fig = plt.figure()
1656+
ax1 = fig.add_subplot(1, 1, 1)
1657+
1658+
data = np.array([[1000, 1100, 1200, 1250],
1659+
[310, 301, 360, 400]])
1660+
1661+
ax2 = ax1.twinx()
1662+
1663+
ax1.plot(data[0], data[1]/1E3, color='#BEAED4')
1664+
ax1.fill_between(data[0], data[1]/1E3, color='#BEAED4', alpha=.8)
1665+
1666+
ax2.plot(data[0], data[1]/1E3, color='#7FC97F')
1667+
ax2.fill_between(data[0], data[1]/1E3, color='#7FC97F', alpha=.5)
1668+
1669+
16491670
@cleanup
16501671
def test_vline_limit():
16511672
fig = plt.figure()

0 commit comments

Comments
 (0)