@@ -177,6 +177,48 @@ def test_twin_inherit_autoscale_setting():
177177 assert ax_y_on .get_autoscaley_on ()
178178 assert not ax_y_off .get_autoscaley_on ()
179179
180+ @cleanup
181+ def test_inverted_cla ():
182+ # Github PR #5450. Setting autoscale should reset
183+ # axes to be non-inverted.
184+ # plotting an image, then 1d graph, axis is now down
185+ fig = plt .figure (0 );
186+ ax = fig .gca ()
187+ # test that a new axis is not inverted per default
188+ assert not (ax .xaxis_inverted ())
189+ assert not (ax .yaxis_inverted ())
190+ img = np .random .random ((100 ,100 ))
191+ ax .imshow (img )
192+ # test that a image axis is inverted
193+ assert not (ax .xaxis_inverted ())
194+ assert ax .yaxis_inverted ()
195+ ax .cla ()
196+ x = np .linspace (0 ,2 * np .pi ,100 );
197+ ax .plot (x ,np .cos (x ))
198+ assert not (ax .xaxis_inverted ())
199+ assert not (ax .yaxis_inverted ())
200+
201+ # autoscaling should not bring back axes to normal
202+ ax .cla ()
203+ ax .imshow (img )
204+ plt .autoscale ()
205+ assert not (ax .xaxis_inverted ())
206+ assert ax .yaxis_inverted ()
207+
208+ # two shared axes. Clearing the master axis should bring axes in shared
209+ # axies back to normal
210+ ax0 = plt .subplot (211 )
211+ ax1 = plt .subplot (212 , sharey = ax0 )
212+ ax0 .imshow (img )
213+ ax1 .plot (x ,np .cos (x ))
214+ ax0 .cla ()
215+ assert not (ax1 .yaxis_inverted ())
216+ ax1 .cla ()
217+ # clearing the nonmaster should not touch limits
218+ ax0 .imshow (img )
219+ ax1 .plot (x ,np .cos (x ))
220+ ax1 .cla ()
221+ assert ax .yaxis_inverted ()
180222
181223@image_comparison (baseline_images = ["minorticks_on_rcParams_both" ],
182224 extensions = ['png' ])
0 commit comments