@@ -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' ])
309353def test_twinx_axis_scales ():
310354 x = np .array ([0 , 0.5 , 1 ])
0 commit comments