55
66RGBAxes to show RGB composite images.
77"""
8+
89import numpy as np
10+ from matplotlib import cbook
911import matplotlib .pyplot as plt
10-
1112from mpl_toolkits .axes_grid1 .axes_rgb import make_rgb_axes , RGBAxes
1213
1314
14- def get_demo_image ():
15- from matplotlib .cbook import get_sample_data
16- f = get_sample_data ("axes_grid/bivariate_normal.npy" , asfileobj = False )
17- z = np .load (f )
18- # z is a numpy array of 15x15
19- return z , (- 3 , 4 , - 4 , 3 )
20-
21-
2215def get_rgb ():
23- Z , extent = get_demo_image ()
16+ f = cbook .get_sample_data ("axes_grid/bivariate_normal.npy" )
17+ Z = np .load (f ) # 15x15 numpy array.
2418
2519 Z [Z < 0 ] = 0.
2620 Z = Z / Z .max ()
@@ -46,7 +40,14 @@ def make_cube(r, g, b):
4640 return R , G , B , RGB
4741
4842
49- def demo_rgb ():
43+ def demo_rgb1 ():
44+ fig = plt .figure ()
45+ ax = RGBAxes (fig , [0.1 , 0.1 , 0.8 , 0.8 ], pad = 0.0 )
46+ r , g , b = get_rgb ()
47+ ax .imshow_rgb (r , g , b )
48+
49+
50+ def demo_rgb2 ():
5051 fig , ax = plt .subplots ()
5152 ax_r , ax_g , ax_b = make_rgb_axes (ax , pad = 0.02 )
5253
@@ -57,26 +58,16 @@ def demo_rgb():
5758 ax_g .imshow (im_g )
5859 ax_b .imshow (im_b )
5960
60-
61- def demo_rgb2 ():
62- fig = plt .figure ()
63- ax = RGBAxes (fig , [0.1 , 0.1 , 0.8 , 0.8 ], pad = 0.0 )
64-
65- r , g , b = get_rgb ()
66- ax .imshow_rgb (r , g , b )
67-
68- for ax1 in [ax .RGB , ax .R , ax .G , ax .B ]:
69- ax1 .tick_params (axis = 'both' , direction = 'in' )
70- for sp1 in ax1 .spines .values ():
61+ for ax in fig .axes :
62+ ax .tick_params (axis = 'both' , direction = 'in' )
63+ for sp1 in ax .spines .values ():
7164 sp1 .set_color ("w" )
72- for tick in ax1 .xaxis .get_major_ticks () + ax1 .yaxis .get_major_ticks ():
65+ for tick in ax .xaxis .get_major_ticks () + ax .yaxis .get_major_ticks ():
7366 tick .tick1line .set_markeredgecolor ("w" )
7467 tick .tick2line .set_markeredgecolor ("w" )
7568
76- return ax
77-
7869
79- demo_rgb ()
70+ demo_rgb1 ()
8071demo_rgb2 ()
8172
8273plt .show ()
0 commit comments