44===========================
55
66"""
7- import matplotlib .pyplot as plt
87
8+ from matplotlib import cbook
9+ import matplotlib .pyplot as plt
910from mpl_toolkits .axes_grid1 .inset_locator import inset_axes , zoomed_inset_axes
1011
1112
12- def get_demo_image ():
13- from matplotlib .cbook import get_sample_data
14- import numpy as np
15- f = get_sample_data ("axes_grid/bivariate_normal.npy" , asfileobj = False )
16- z = np .load (f )
17- # z is a numpy array of 15x15
18- return z , (- 3 , 4 , - 4 , 3 )
19-
20-
2113fig , ax = plt .subplots (figsize = [5 , 4 ])
2214
23- Z , extent = get_demo_image ()
24-
25- ax .set (aspect = 1 ,
26- xlim = (- 15 , 15 ),
27- ylim = (- 20 , 5 ))
15+ Z = cbook .get_sample_data ("axes_grid/bivariate_normal.npy" , np_load = True )
16+ extent = (- 3 , 4 , - 4 , 3 )
2817
18+ ax .set (aspect = 1 , xlim = (- 15 , 15 ), ylim = (- 20 , 5 ))
2919
3020axins = zoomed_inset_axes (ax , zoom = 2 , loc = 'upper left' )
3121im = axins .imshow (Z , extent = extent , origin = "lower" )
3222
3323plt .xticks (visible = False )
3424plt .yticks (visible = False )
3525
36-
3726# colorbar
3827cax = inset_axes (axins ,
3928 width = "5%" , # width = 10% of parent_bbox width
@@ -43,7 +32,6 @@ def get_demo_image():
4332 bbox_transform = axins .transAxes ,
4433 borderpad = 0 ,
4534 )
46-
4735fig .colorbar (im , cax = cax )
4836
4937plt .show ()
0 commit comments