8000 Merge pull request #18393 from QuLogic/twin-scale · QuLogic/matplotlib@3e13f81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e13f81

Browse files
authored
Merge pull request matplotlib#18393 from QuLogic/twin-scale
Fix Axis scale on twinned Axes.
2 parents 296de82 + 166a609 commit 3e13f81

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ def __init__(self, fig, rect,
494494
self._anchor = 'C'
495495
self._stale_viewlim_x = False
496496
self._stale_viewlim_y = False
497< 10000 /code>-
self._sharex = None
498-
self._sharey = None
497+
self._sharex = sharex
498+
self._sharey = sharey
499499
self.set_label(label)
500500
self.set_figure(fig)
501501
self.set_box_aspect(box_aspect)
@@ -516,11 +516,6 @@ def __init__(self, fig, rect,
516516
self._rasterization_zorder = None
517517
self.cla()
518518

519-
if sharex is not None:
520-
self.sharex(sharex)
521-
if sharey is not None:
522-
self.sharey(sharey)
523-
524519
# funcs used to format x and y - fall back on major formatters
525520
self.fmt_xdata = None
526521
self.fmt_ydata = None

lib/matplotlib/tests/test_axes.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,50 @@ def test_twinx_cla():
305305
assert ax.yaxis.get_visible()
306306

307307

308+
@pytest.mark.parametrize('twin', ('x', 'y'))
309+
@check_figures_equal(extensions=['png'], tol=0.19)
310+
def test_twin_logscale(fig_test, fig_ref, twin):
311+
twin_func = f'twin{twin}' # test twinx or twiny
312+
set_scale = f'set_{twin}scale'
313+
x = np.arange(1, 100)
314+
315+
# Change scale after twinning.
316+
ax_test = fig_test.add_subplot(2, 1, 1)
317+
ax_twin = getattr(ax_test, twin_func)()
318+
getattr(ax_test, set_scale)('log')
319+
ax_twin.plot(x, x)
320+
321+
# Twin after changing scale.
322+
ax_test = fig_test.add_subplot(2, 1, 2)
323+
getattr(ax_test, set_scale)('log')
324+
ax_twin = getattr(ax_test, twin_func)()
325+
ax_twin.plot(x, x)
326+
327+
for i in [1, 2]:
328+
ax_ref = fig_ref.add_subplot(2, 1, i)
329+
getattr(ax_ref, set_scale)('log')
330+
ax_ref.plot(x, x)
331+
332+
# This is a hack because twinned Axes double-draw the frame.
333+
# Remove this when that is fixed.
334+
Path = matplotlib.path.Path
335+
fig_ref.add_artist(
336+
matplotlib.patches.PathPatch(
337+
Path([[0, 0], [0, 1],
338+
[0, 1], [1, 1],
339+
[1, 1], [1, 0],
340+
[1, 0], [0, 0]],
341+
[Path.MOVETO, Path.LINETO] * 4),
342+
transform=ax_ref.transAxes,
343+
facecolor='none',
344+
edgecolor=mpl.rcParams['axes.edgecolor'],
345+
linewidth=mpl.rcParams['axes.linewidth'],
346+
capstyle='projecting'))
347+
348+
remove_ticks_and_titles(fig_test)
349+
remove_ticks_and_titles(fig_ref)
350+
351+
308352
@image_comparison(['twin_autoscale.png'])
309353
def test_twinx_axis_scales():
310354
x = np.array([0, 0.5, 1])

0 commit comments

Comments
 (0)
0