55
66import numpy as np
77from .axes_divider import make_axes_locatable , Size , locatable_axes_factory
8+ import sys
9+ import warnings
810
911def make_rgb_axes (ax , pad = 0.01 , axes_class = None , add_all = True ):
1012 """
@@ -75,17 +77,59 @@ def imshow_rgb(ax, r, g, b, **kwargs):
7577from .mpl_axes import Axes
7678
7779class RGBAxesBase (object ):
78-
80+ """base class for a 4-panel imshow (RGB, R, G, B)
81+
82+ Layout:
83+ +---------------+-----+
84+ | | R |
85+ + +-----+
86+ | RGB | G |
87+ + +-----+
88+ | | B |
89+ +---------------+-----+
90+
91+ Attributes
92+ ----------
93+ _defaultAxesClass : matplotlib.axes.Axes
94+ defaults to 'Axes' in RGBAxes child class.
95+ No default in abstract base class
96+ RGB : _defaultAxesClass
97+ The axes object for the three-channel imshow
98+ R : _defaultAxesClass
99+ The axes object for the red channel imshow
100+ G : _defaultAxesClass
101+ The axes object for the green channel imshow
102+ B : _defaultAxesClass
103+ The axes object for the blue channel imshow
104+ """
79105 def __init__ (self , * kl , ** kwargs ):
106+ """
107+ Parameters
108+ ----------
109+ pad : float
110+ fraction of the axes height to put as padding.
111+ defaults to 0.0
112+ add_all : bool
113+ True: Add the {rgb, r, g, b} axes to the figure
114+ defaults to True.
115+ axes_class : matplotlib.axes.Axes
116+
117+ kl :
118+ Unpacked into axes_class() init for RGB
119+ kwargs :
120+ Unpacked into axes_class() init for RGB, R, G, B axes
121+ """
80122 pad = kwargs .pop ("pad" , 0.0 )
81123 add_all = kwargs .pop ("add_all" , True )
82- axes_class = kwargs .pop ("axes_class" , None )
83-
84-
85-
86-
87- if axes_class is None :
88- axes_class = self ._defaultAxesClass
124+ try :
125+ axes_class = kwargs .pop ("axes_class" , self ._defaultAxesClass )
126+ except AttributeError :
127+ new_msg = ("A subclass of RGBAxesBase must have a "
128+ "_defaultAxesClass attribute. If you are not sure which "
129+ "axes class to use, consider using "
130+ "mpl_toolkits.axes_grid1.mpl_axes.Axes." )
131+ six .reraise (KeyError , AttributeError (new_msg ),
132+ sys .exc_info ()[2 ])
89133
90134 ax = axes_class (* kl , ** kwargs )
91135
@@ -109,11 +153,6 @@ def __init__(self, *kl, **kwargs):
109153 locator = divider .new_locator (nx = 2 , ny = ny )
110154 ax1 .set_axes_locator (locator )
111155 ax1 .axis [:].toggle (ticklabels = False )
112- #for t in ax1.yaxis.get_ticklabels() + ax1.xaxis.get_ticklabels():
113- # t.set_visible(False)
114- #if hasattr(ax1, "_axislines"):
115- # for axisline in ax1._axislines.values():
116- # axisline.major_ticklabels.set_visible(False)
117156 ax_rgb .append (ax1 )
118157
119158 self .RGB = ax
@@ -126,25 +165,49 @@ def __init__(self, *kl, **kwargs):
126165
127166 self ._config_axes ()
128167
129- def _config_axes (self ):
130- for ax1 in [self .RGB , self .R , self .G , self .B ]:
131- #for sp1 in ax1.spines.values():
132- # sp1.set_color("w")
133- ax1 .axis [:].line .set_color ("w" )
134- ax1 .axis [:].major_ticks .set_mec ("w" )
135- # for tick in ax1.xaxis.get_major_ticks() + ax1.yaxis.get_major_ticks():
136- # tick.tick1line.set_mec("w")
137- # tick.tick2line.set_mec("w")
138-
168+ def _config_axes (self , line_color = 'w' , marker_edge_color = 'w' ):
169+ """Set the line color and ticks for the axes
139170
171+ Parameters
172+ ----------
173+ line_color : any matplotlib color
174+ marker_edge_color : any matplotlib color
175+ """
176+ for ax1 in [self .RGB , self .R , self .G , self .B ]:
177+ ax1 .axis [:].line .set_color (line_color )
178+ ax1 .axis [:].major_ticks .set_markeredgecolor (marker_edge_color )
140179
141180 def add_RGB_to_figure (self ):
181+ """Add the red, green and blue axes to the RGB composite's axes figure
182+ """
142183 self .RGB .get_figure ().add_axes (self .R )
143184 self .RGB .get_figure ().add_axes (self .G )
144185 self .RGB .get_figure ().add_axes (self .B )
145186
146187 def imshow_rgb (self , r , g , b , ** kwargs ):
188+ """Create the four images {rgb, r, g, b}
189+
190+ Parameters
191+ ----------
192+ r : array-like
193+ The red array
194+ g : array-like
195+ The green array
196+ b : array-like
197+ The blue array
198+ kwargs : imshow kwargs
199+ kwargs get unpacked into the imshow calls for the four images
200+
201+ Returns
202+ -------
203+ rgb : matplotlib.image.AxesImage
204+ r : matplotlib.image.AxesImage
205+ g : matplotlib.image.AxesImage
206+ b : matplotlib.image.AxesImage
207+ """
147208 ny , nx = r .shape
209+ assert ((nx , ny ) == g .shape == b .shape )
210+
148211 R = np .zeros ([ny , nx , 3 ], dtype = "d" )
149212 R [:,:,0 ] = r
150213 G = np .zeros_like (R )
0 commit comments