5
5
6
6
import numpy as np
7
7
from .axes_divider import make_axes_locatable , Size , locatable_axes_factory
8
+ import sys
9
+ from .mpl_axes import Axes
10
+
8
11
9
12
def make_rgb_axes (ax , pad = 0.01 , axes_class = None , add_all = True ):
10
13
"""
@@ -53,8 +56,6 @@ def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True):
53
56
54
57
return ax_rgb
55
58
56
- #import matplotlib.axes as maxes
57
-
58
59
59
60
def imshow_rgb (ax , r , g , b , ** kwargs ):
60
61
ny , nx = r .shape
@@ -72,20 +73,60 @@ def imshow_rgb(ax, r, g, b, **kwargs):
72
73
return im_rgb
73
74
74
75
75
- from .mpl_axes import Axes
76
-
77
76
class RGBAxesBase (object ):
78
8000
code>
-
77
+ """base class for a 4-panel imshow (RGB, R, G, B)
78
+
79
+ Layout:
80
+ +---------------+-----+
81
+ | | R |
82
+ + +-----+
83
+ | RGB | G |
84
+ + +-----+
85
+ | | B |
86
+ +---------------+-----+
87
+
88
+ Attributes
89
+ ----------
90
+ _defaultAxesClass : matplotlib.axes.Axes
91
+ defaults to 'Axes' in RGBAxes child class.
92
+ No default in abstract base class
93
+ RGB : _defaultAxesClass
94
+ The axes object for the three-channel imshow
95
+ R : _defaultAxesClass
96
+ The axes object for the red channel imshow
97
+ G : _defaultAxesClass
98
+ The axes object for the green channel imshow
99
+ B : _defaultAxesClass
100
+ The axes object for the blue channel imshow
101
+ """
79
102
def __init__ (self , * kl , ** kwargs ):
103
+ """
104
+ Parameters
105
+ ----------
106
+ pad : float
107
+ fraction of the axes height to put as padding.
108
+ defaults to 0.0
109
+ add_all : bool
110
+ True: Add the {rgb, r, g, b} axes to the figure
111
+ defaults to True.
112
+ axes_class : matplotlib.axes.Axes
113
+
114
+ kl :
115
+ Unpacked into axes_class() init for RGB
116
+ kwargs :
117
+ Unpacked into axes_class() init for RGB, R, G, B axes
118
+ """
80
119
pad = kwargs .pop ("pad" , 0.0 )
81
120
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
121
+ try :
122
+ axes_class = kwargs .pop ("axes_class" , self ._defaultAxesClass )
123
+ except AttributeError :
124
+ new_msg = ("A subclass of RGBAxesBase must have a "
125
+ "_defaultAxesClass attribute. If you are not sure which "
126
+ "axes class to use, consider using "
127
+ "mpl_toolkits.axes_grid1.mpl_axes.Axes." )
128
+ six .reraise (AttributeError , AttributeError (new_msg ),
129
+ sys .exc_info ()[2 ])
89
130
90
131
ax = axes_class (* kl , ** kwargs )
91
132
@@ -109,11 +150,6 @@ def __init__(self, *kl, **kwargs):
109
150
locator = divider .new_locator (nx = 2 , ny = ny )
110
151
ax1 .set_axes_locator (locator )
111
152
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)
117
153
ax_rgb .append (ax1 )
118
154
119
155
self .RGB = ax
@@ -126,25 +162,54 @@ def __init__(self, *kl, **kwargs):
126
162
127
163
self ._config_axes ()
128
164
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
-
165
+ def _config_axes (self , line_color = 'w' , marker_edge_color = 'w' ):
166
+ """Set the line color and ticks for the axes
139
167
168
+ Parameters
169
+ ----------
170
+ line_color : any matplotlib color
171
+ marker_edge_color : any matplotlib color
172
+ """
173
+ for ax1 in [self .RGB , self .R , self .G , self .B ]:
174
+ ax1 .axis [:].line .set_color (line_color )
175
+ ax1 .axis [:].major_ticks .set_markeredgecolor (marker_edge_color )
140
176
141
177
def add_RGB_to_figure (self ):
178
+ """Add the red, green and blue axes to the RGB composite's axes figure
179
+ """
142
180
self .RGB .get_figure ().add_axes (self .R )
143
181
self .RGB .get_figure ().add_axes (self .G )
144
182
self .RGB .get_figure ().add_axes (self .B )
145
183
146
184
def imshow_rgb (self , r , g , b , ** kwargs ):
185
+ """Create the four images {rgb, r, g, b}
186
+
187
+ Parameters
188
+ ----------
189
+ r : array-like
190
+ The red array
191
+ g : array-like
192
+ The green array
193
+ b : array-like
194
+ The blue array
195
+ kwargs : imshow kwargs
196
+ kwargs get unpacked into the imshow calls for the four images
197
+
198
+ Returns
199
+ -------
200
+ rgb : matplotlib.image.AxesImage
201
+ r : matplotlib.image.AxesImage
202
+ g : matplotlib.image.AxesImage
203
+ b : matplotlib.image.AxesImage
204
+ """
147
205
ny , nx = r .shape
206
+ if not ((nx , ny ) == g .shape == b .shape ):
207
+ raise ValueError ('Input shapes do not match.'
208
+ '\n r.shape = {}'
209
+ '\n g.shape = {}'
210
+ '\n b.shape = {}'
211
+ '' .format (r .shape , g .shape , b .shape ))
212
+
148
213
R = np .zeros ([ny , nx , 3 ], dtype = "d" )
149
214
R [:,:,0 ] = r
150
215
G = np .zeros_like (R )
0 commit comments