Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ae0b6f3

Browse filesBrowse files
committed
DOC/MNT: Throwing some docstrings at axes_rgb.py
In my learning how to use axes_rgb.py, I ended up writing some docstrings. Hope this is useful.
1 parent 326ccd6 commit ae0b6f3
Copy full SHA for ae0b6f3

File tree

Expand file treeCollapse file tree

2 files changed

+90
-28
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+90
-28
lines changed

‎lib/mpl_toolkits/axes_grid1/axes_rgb.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/axes_rgb.py
+86-23Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import numpy as np
77
from .axes_divider import make_axes_locatable, Size, locatable_axes_factory
8+
import sys
9+
import warnings
810

911
def 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):
7577
from .mpl_axes import Axes
7678

7779
class 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)

‎lib/mpl_toolkits/axes_grid1/mpl_axes.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/mpl_axes.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ def __init__(self, axes):
3333

3434
def __getitem__(self, k):
3535
if isinstance(k, tuple):
36-
r = SimpleChainedObjects([dict.__getitem__(self, k1) for k1 in k])
36+
r = SimpleChainedObjects(
37+
[super(Axes.AxisDict, self).__getitem__(self, k1)
38+
for k1 in k])
3739
return r
3840
elif isinstance(k, slice):
39-
if k.start == None and k.stop == None and k.step == None:
41+
if k.start is None and k.stop is None and k.step is None:
4042
r = SimpleChainedObjects(list(six.itervalues(self)))
4143
return r
4244
else:
@@ -47,12 +49,9 @@ def __getitem__(self, k):
4749
def __call__(self, *v, **kwargs):
4850
return maxes.Axes.axis(self.axes, *v, **kwargs)
4951

50-
5152
def __init__(self, *kl, **kw):
5253
super(Axes, self).__init__(*kl, **kw)
5354

54-
55-
5655
def _init_axis_artists(self, axes=None):
5756
if axes is None:
5857
axes = self

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.