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 d1e0709

Browse filesBrowse files
committed
Merge pull request #4564 from ericdill/axes-rgb-docs
DOC/MNT: Throwing some docstrings at axes_rgb.py
2 parents 484c72b + 640743f commit d1e0709
Copy full SHA for d1e0709

File tree

Expand file treeCollapse file tree

2 files changed

+97
-33
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+97
-33
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
+92-27Lines changed: 92 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
import numpy as np
77
from .axes_divider import make_axes_locatable, Size, locatable_axes_factory
8+
import sys
9+
from .mpl_axes import Axes
10+
811

912
def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True):
1013
"""
@@ -53,8 +56,6 @@ def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True):
5356

5457
return ax_rgb
5558

56-
#import matplotlib.axes as maxes
57-
5859

5960
def imshow_rgb(ax, r, g, b, **kwargs):
6061
ny, nx = r.shape
@@ -72,20 +73,60 @@ def imshow_rgb(ax, r, g, b, **kwargs):
7273
return im_rgb
7374

7475

75-
from .mpl_axes import Axes
76-
7776
class RGBAxesBase(object):
78-
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+
"""
79102
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+
"""
80119
pad = kwargs.pop("pad", 0.0)
81120
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])
89130

90131
ax = axes_class(*kl, **kwargs)
91132

@@ -109,11 +150,6 @@ def __init__(self, *kl, **kwargs):
109150
locator = divider.new_locator(nx=2, ny=ny)
110151
ax1.set_axes_locator(locator)
111152
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)
117153
ax_rgb.append(ax1)
118154

119155
self.RGB = ax
@@ -126,25 +162,54 @@ def __init__(self, *kl, **kwargs):
126162

127163
self._config_axes()
128164

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
139167
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)
140176

141177
def add_RGB_to_figure(self):
178+
"""Add the red, green and blue axes to the RGB composite's axes figure
179+
"""
142180
self.RGB.get_figure().add_axes(self.R)
143181
self.RGB.get_figure().add_axes(self.G)
144182
self.RGB.get_figure().add_axes(self.B)
145183

146184
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+
"""
147205
ny, nx = r.shape
206+
if not ((nx, ny) == g.shape == b.shape):
207+
raise ValueError('Input shapes do not match.'
208+
'\nr.shape = {}'
209+
'\ng.shape = {}'
210+
'\nb.shape = {}'
211+
''.format(r.shape, g.shape, b.shape))
212+
148213
R = np.zeros([ny, nx, 3], dtype="d")
149214
R[:,:,0] = r
150215
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
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ 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__(k1) for k1 in k])
3738
return r
3839
elif isinstance(k, slice):
39-
if k.start == None and k.stop == None and k.step == None:
40+
if k.start is None and k.stop is None and k.step is None:
4041
r = SimpleChainedObjects(list(six.itervalues(self)))
4142
return r
4243
else:
@@ -47,12 +48,9 @@ def __getitem__(self, k):
4748
def __call__(self, *v, **kwargs):
4849
return maxes.Axes.axis(self.axes, *v, **kwargs)
4950

50-
5151
def __init__(self, *kl, **kw):
5252
super(Axes, self).__init__(*kl, **kw)
5353

54-
55-
5654
def _init_axis_artists(self, axes=None):
5755
if axes is None:
5856
axes = self
@@ -153,7 +151,8 @@ def toggle(self, all=None, ticks=None, ticklabels=None, label=None):
153151

154152

155153
if __name__ == '__main__':
156-
fig = figure()
154+
import matplotlib.pyplot as plt
155+
fig = plt.figure()
157156
ax = Axes(fig, [0.1, 0.1, 0.8, 0.8])
158157
fig.add_axes(ax)
159158
ax.cla()

0 commit comments

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