Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ def __init__(self, fig, rect,
self._anchor = 'C'
self._stale_viewlim_x = False
self._stale_viewlim_y = False
self._sharex = None
self._sharey = None
self._sharex = sharex
self._sharey = sharey
self.set_label(label)
self.set_figure(fig)
self.set_box_aspect(box_aspect)
Expand All @@ -510,11 +510,6 @@ def __init__(self, fig, rect,
self._rasterization_zorder = None
self.cla()

if sharex is not None:
self.sharex(sharex)
if sharey is not None:
self.sharey(sharey)

# funcs used to format x and y - fall back on major formatters
self.fmt_xdata = None
self.fmt_ydata = None
Expand Down
44 changes: 44 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,50 @@ def test_twinx_cla():
assert ax.yaxis.get_visible()


@pytest.mark.parametrize('twin', ('x', 'y'))
@check_figures_equal(extensions=['png'], tol=0.19)
def test_twin_logscale(fig_test, fig_ref, twin):
twin_func = f'twin{twin}' # test twinx or twiny
set_scale = f'set_{twin}scale'
x = np.arange(1, 100)

# Change scale after twinning.
ax_test = fig_test.add_subplot(2, 1, 1)
ax_twin = getattr(ax_test, twin_func)()
getattr(ax_test, set_scale)('log')
ax_twin.plot(x, x)

# Twin after changing scale.
ax_test = fig_test.add_subplot(2, 1, 2)
getattr(ax_test, set_scale)('log')
ax_twin = getattr(ax_test, twin_func)()
ax_twin.plot(x, x)

for i in [1, 2]:
ax_ref = fig_ref.add_subplot(2, 1, i)
getattr(ax_ref, set_scale)('log')
ax_ref.plot(x, x)

# This is a hack because twinned Axes double-draw the frame.
# Remove this when that is fixed.
Path = matplotlib.path.Path
fig_ref.add_artist(
matplotlib.patches.PathPatch(
Path([[0, 0], [0, 1],
[0, 1], [1, 1],
[1, 1], [1, 0],
[1, 0], [0, 0]],
[Path.MOVETO, Path.LINETO] * 4),
transform=ax_ref.transAxes,
facecolor='none',
edgecolor=mpl.rcParams['axes.edgecolor'],
linewidth=mpl.rcParams['axes.linewidth'],
capstyle='projecting'))

remove_ticks_and_titles(fig_test)
remove_ticks_and_titles(fig_ref)


@image_comparison(['twin_autoscale.png'])
def test_twinx_axis_scales():
x = np.array([0, 0.5, 1])
Expand Down