Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52434ff

Browse files
committed
Strip whitespace and strict PEP8 compliance
1 parent 0db6341 commit 52434ff

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

lib/matplotlib/colors.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,15 +1457,16 @@ def hsv_to_rgb(hsv):
14571457

14581458
return rgb
14591459

1460+
14601461
class LightSource(object):
14611462
"""
14621463
Create a light source coming from the specified azimuth and elevation.
14631464
Angles are in degrees, with the azimuth measured
14641465
clockwise from north and elevation up from the zero plane of the surface.
14651466
14661467
The :meth:`shade` is used to produce "shaded" rgb values for a data array.
1467-
:meth:`shade_rgb` can be used to combine an rgb image with
1468-
The :meth:`shade_rgb`
1468+
:meth:`shade_rgb` can be used to combine an rgb image with
1469+
The :meth:`shade_rgb`
14691470
The :meth:`hillshade` produces an illumination map of a surface.
14701471
"""
14711472
def __init__(self, azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1,
@@ -1486,7 +1487,7 @@ def __init__(self, azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1,
14861487
14871488
Notes
14881489
-----
1489-
For backwards compatibility, the parameters *hsv_min_val*,
1490+
For backwards compatibility, the parameters *hsv_min_val*,
14901491
*hsv_max_val*, *hsv_min_sat*, and *hsv_max_sat* may be supplied at
14911492
initialization as well. However, these parameters will only be used if
14921493
"blend_mode='hsv'" is passed into :meth:`shade` or :meth:`shade_rgb`.
@@ -1502,12 +1503,12 @@ def __init__(self, azdeg=315, altdeg=45, hsv_min_val=0, hsv_max_val=1,
15021503
def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15031504
"""
15041505
Calculates the illumination intensity for a surface using the defined
1505-
azimuth and elevation for the light source.
1506-
1506+
azimuth and elevation for the light source.
1507+
15071508
Imagine an artificial sun placed at infinity in some azimuth and
15081509
elevation position illuminating our surface. The parts of the surface
15091510
that slope toward the sun should brighten while those sides facing away
1510-
should become darker.
1511+
should become darker.
15111512
15121513
Parameters
15131514
----------
@@ -1549,8 +1550,8 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15491550
dy, dx = np.gradient(vert_exag * elevation, dy, dx)
15501551
slope = 0.5 * np.pi - np.arctan(np.hypot(dx, dy))
15511552
aspect = np.arctan2(dx, dy)
1552-
intensity = (np.sin(alt) * np.sin(slope)
1553-
+ np.cos(alt) * np.cos(slope)
1553+
intensity = (np.sin(alt) * np.sin(slope)
1554+
+ np.cos(alt) * np.cos(slope)
15541555
* np.cos(az - aspect))
15551556

15561557
# Apply contrast stretch
@@ -1565,10 +1566,10 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15651566

15661567
return intensity
15671568

1568-
def shade(self, data, cmap, norm=None, blend_mode='hsv',
1569+
def shade(self, data, cmap, norm=None, blend_mode='hsv',
15691570
vert_exag=1, dx=1, dy=1, fraction=1, **kwargs):
15701571
"""
1571-
Combine colormapped data values with an illumination intensity map
1572+
Combine colormapped data values with an illumination intensity map
15721573
(a.k.a. "hillshade") of the values.
15731574
15741575
Parameters
@@ -1587,7 +1588,7 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
15871588
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
15881589
The type of blending used to combine the colormapped data values
15891590
with the illumination intensity. For backwards compatibility, this
1590-
defaults to "hsv". Note that for most topographic surfaces,
1591+
defaults to "hsv". Note that for most topographic surfaces,
15911592
"overlay" or "soft" appear more visually realistic. If a
15921593
user-defined function is supplied, it is expected to combine an
15931594
MxNx3 RGB array of floats (ranging 0 to 1) with an MxNx1 hillshade
@@ -1610,8 +1611,8 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
16101611
full illumination or shadow (and clipping any values that move
16111612
beyond 0 or 1). Note that this is not visually or mathematically
16121613
the same as vertical exaggeration.
1613-
Additional kwargs are passed on to the *blend_mode* function.
1614-
1614+
Additional kwargs are passed on to the *blend_mode* function.
1615+
16151616
Returns
16161617
-------
16171618
rgba : ndarray
@@ -1621,14 +1622,14 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
16211622
norm = Normalize(vmin=data.min(), vmax=data.max())
16221623

16231624
rgb0 = cmap(norm(data))
1624-
rgb1 = self.shade_rgb(rgb0, elevation=data, blend_mode=blend_mode,
1625+
rgb1 = self.shade_rgb(rgb0, elevation=data, blend_mode=blend_mode,
16251626
vert_exag=vert_exag, dx=dx, dy=dy,
16261627
fraction=fraction, **kwargs)
16271628
# Don't overwrite the alpha channel, if present.
16281629
rgb0[..., :3] = rgb1[..., :3]
16291630
return rgb0
16301631

1631-
def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
1632+
def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
16321633
vert_exag=1, dx=1, dy=1, **kwargs):
16331634
"""
16341635
Take the input RGB array (ny*nx*3) adjust their color values
@@ -1652,7 +1653,7 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
16521653
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
16531654
The type of blending used to combine the colormapped data values
16541655
with the illumination intensity. For backwards compatibility, this
1655-
defaults to "hsv". Note that for most topographic surfaces,
1656+
defaults to "hsv". Note that for most topographic surfaces,
16561657
"overlay" or "soft" appear more visually realistic. If a
16571658
user-defined function is supplied, it is expected to combine an
16581659
MxNx3 RGB array of floats (ranging 0 to 1) with an MxNx1 hillshade
@@ -1669,8 +1670,8 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
16691670
The x-spacing (columns) of the input *elevation* grid.
16701671
dy : number, optional
16711672
The y-spacing (rows) of the input *elevation* grid.
1672-
Additional kwargs are passed on to the *blend_mode* function.
1673-
1673+
Additional kwargs are passed on to the *blend_mode* function.
1674+
16741675
Returns
16751676
-------
16761677
shaded_rgb : ndarray
@@ -1682,9 +1683,9 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
16821683

16831684
# Blend the hillshade and rgb data using the specified mode
16841685
lookup = {
1685-
'hsv':self.blend_hsv,
1686-
'soft':self.blend_soft_light,
1687-
'overlay':self.blend_overlay,
1686+
'hsv': self.blend_hsv,
1687+
'soft': self.blend_soft_light,
1688+
'overlay': self.blend_overlay,
16881689
}
16891690
if blend_mode in lookup:
16901691
return lookup[blend_mode](rgb, intensity, **kwargs)
@@ -1794,7 +1795,7 @@ def blend_soft_light(self, rgb, intensity):
17941795
rgb : ndarray
17951796
An MxNx3 RGB array representing the combined images.
17961797
"""
1797-
return 2 * intensity * rgb + (1 - 2 * intensity) * rgb**2
1798+
return 2 * intensity * rgb + (1 - 2 * intensity) * rgb**2
17981799

17991800
def blend_overlay(self, rgb, intensity):
18001801
"""
@@ -1816,6 +1817,7 @@ def blend_overlay(self, rgb, intensity):
18161817
high = 1 - 2 * (1 - intensity) * (1 - rgb)
18171818
return np.where(rgb <= 0.5, low, high)
18181819

1820+
18191821
def from_levels_and_colors(levels, colors, extend='neither'):
18201822
"""
18211823
A helper routine to generate a cmap and a norm instance which

0 commit comments

Comments
 (0)