99from mpl_toolkits .axes_grid1 .inset_locator import inset_axes , zoomed_inset_axes
1010from mpl_toolkits .axes_grid1 .colorbar import colorbar
1111
12+
1213def get_demo_image ():
1314 from matplotlib .cbook import get_sample_data
1415 import numpy as np
1516 f = get_sample_data ("axes_grid/bivariate_normal.npy" , asfileobj = False )
1617 z = np .load (f )
1718 # z is a numpy array of 15x15
18- return z , (- 3 ,4 , - 4 ,3 )
19+ return z , (- 3 , 4 , - 4 , 3 )
1920
2021
21- fig = plt .figure (1 , [5 ,4 ])
22- ax = fig .add_subplot (111 )
22+ fig , ax = plt .subplots (figsize = [5 , 4 ])
2323
2424Z , extent = get_demo_image ()
2525
@@ -28,7 +28,7 @@ def get_demo_image():
2828 ylim = (- 20 , 5 ))
2929
3030
31- axins = zoomed_inset_axes (ax , 2 , loc = 2 ) # zoom = 6
31+ axins = zoomed_inset_axes (ax , 2 , loc = 2 ) # zoom = 6
3232im = axins .imshow (Z , extent = extent , interpolation = "nearest" ,
3333 origin = "lower" )
3434
@@ -38,17 +38,14 @@ def get_demo_image():
3838
3939# colorbar
4040cax = inset_axes (axins ,
41- width = "5%" , # width = 10% of parent_bbox width
42- height = "100%" , # height : 50%
41+ width = "5%" , # width = 10% of parent_bbox width
42+ height = "100%" , # height : 50%
4343 loc = 3 ,
4444 bbox_to_anchor = (1.05 , 0. , 1 , 1 ),
4545 bbox_transform = axins .transAxes ,
4646 borderpad = 0 ,
4747 )
4848
49+ colorbar (im , cax = cax )
4950
50- colorbar (im , cax = cax ) #, ticks=[1,2,3])
51-
52-
53- plt .draw ()
5451plt .show ()
0 commit comments