@@ -298,6 +298,33 @@ def test_colorbar_ticks():
298298 assert len (cbar .ax .xaxis .get_ticklocs ()) == len (clevs )
299299
300300
301+ @cleanup
302+ def test_colorbar_get_ticks ():
303+ # test feature for #5792
304+ plt .figure ()
305+ data = np .arange (1200 ).reshape (30 , 40 )
306+ levels = [0 , 200 , 400 , 600 , 800 , 1000 , 1200 ]
307+
308+ plt .subplot ()
309+ plt .contourf (data , levels = levels )
310+
311+ # testing getter for user set ticks
312+ userTicks = plt .colorbar (ticks = [0 , 600 , 1200 ])
313+ assert userTicks .get_ticks ().tolist () == [0 , 600 , 1200 ]
314+
315+ # testing for getter after calling set_ticks
316+ userTicks .set_ticks ([600 , 700 , 800 ])
317+ assert userTicks .get_ticks ().tolist () == [600 , 700 , 800 ]
318+
319+ # testing for getter after calling set_ticks with some ticks out of bounds
320+ userTicks .set_ticks ([600 , 1300 , 1400 , 1500 ])
321+ assert userTicks .get_ticks ().tolist () == [600 ]
322+
323+ # testing getter when no ticks are assigned
324+ defTicks = plt .colorbar (orientation = 'horizontal' )
325+ assert defTicks .get_ticks ().tolist () == levels
326+
327+
301328if __name__ == '__main__' :
302329 import nose
303330 nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments