Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

PiecewiseLinearNorm#5061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
05c1b76
ENH: Add OffsetNorm and tests
phobsonNov 27, 2014
8ad54f3
fix OffsetNorm docstring to numpydoc spec
phobsonMar 30, 2015
03e506c
OffsetNorm blurb in whats_new
phobsonMar 30, 2015
04ea107
removed OffsetNorm.inverse method
phobsonJun 6, 2015
62c9efc
attempting to create a baseline image
phobsonJun 6, 2015
d95db3c
fix bad indexing when returning a scalar
phobsonJun 8, 2015
3cc84a6
the real test image
phobsonJun 8, 2015
47c447a
refactor tests a bit to handle non-invertable Norms
phobsonJun 8, 2015
36042b6
OffsetNorm -> PiecewiseLinearNorm
dopplershiftJul 11, 2015
56cbae2
Propagate mask from input data
jkseppanSep 3, 2015
1d1ff98
Remove unused clip parameter
jkseppanSep 3, 2015
14b6837
Use process_value in PiecewiseLinearNorm
jkseppanSep 3, 2015
a8d4956
Return a scalar when passed in a scalar
jkseppanSep 3, 2015
31bfd2a
Return 0.5 for vcenter == vmax
jkseppanSep 3, 2015
a68fff3
pep8 fixes
jkseppanSep 3, 2015
3293971
PiecewiseLinearNorm
OceanWolfSep 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
OffsetNorm -> PiecewiseLinearNorm
  • Loading branch information
@dopplershift@OceanWolf
dopplershift authored andOceanWolf committedSep 13, 2015
commit36042b6c800afab3f419b9b513069e4a1107f76e
2 changes: 1 addition & 1 deletiondoc/users/whats_new.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,7 @@ determines the placement of the arrow head along the quiver line.

Offset Normalizers for Colormaps
````````````````````````````````
Paul Hobson/Geosyntec Consultants added a new :class:`matplotlib.colors.OffsetNorm`
Paul Hobson/Geosyntec Consultants added a new :class:`matplotlib.colors.PiecewiseLinearNorm`
class with the help of Till Stensitzki. This is particularly useful when using a
diverging colormap on data that are asymetrically centered around a logical value
(e.g., 0 when data range from -2 to 4).
Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/colors.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -964,7 +964,7 @@ def scaled(self):
return (self.vmin is not None and self.vmax is not None)


classOffsetNorm(Normalize):
classPiecewiseLinearNorm(Normalize):
"""
A subclass of matplotlib.colors.Normalize.

Expand DownExpand Up@@ -998,7 +998,7 @@ def __init__(self, vmin=None, vcenter=None, vmax=None, clip=False):
Examples
--------
>>> import matplotlib.colors as mcolors
>>> offset = mcolors.OffsetNorm(vmin=-2., vcenter=0., vmax=4.)
>>> offset = mcolors.PiecewiseLinearNorm(vmin=-2., vcenter=0., vmax=4.)
>>> data = [-2., -1., 0., 1., 2., 3., 4.]
>>> offset(data)
array([0., 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
Expand Down
46 changes: 23 additions & 23 deletionslib/matplotlib/tests/test_colors.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -227,44 +227,44 @@ def test_process_value_array(self):
assert_array_equal(res, np.array([5., 10.]))


classBaseOffsetNorm(BaseNormMixin):
normclass = mcolors.OffsetNorm
classBasePiecewiseLinearNorm(BaseNormMixin):
normclass = mcolors.PiecewiseLinearNorm
test_inverse = False

classtest_OffsetNorm_Even(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_Even(BasePiecewiseLinearNorm):
def setup(self):
self.norm = self.normclass(vmin=-1, vcenter=0, vmax=4)
self.vals = np.array([-1.0, -0.5, 0.0, 1.0, 2.0, 3.0, 4.0])
self.expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])


classtest_OffsetNorm_Odd(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_Odd(BasePiecewiseLinearNorm):
def setup(self):
self.normclass = mcolors.OffsetNorm
self.normclass = mcolors.PiecewiseLinearNorm
self.norm = self.normclass(vmin=-2, vcenter=0, vmax=5)
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
self.expected = np.array([0.0, 0.25, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])


classtest_OffsetNorm_AllNegative(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_AllNegative(BasePiecewiseLinearNorm):
def setup(self):
self.normclass = mcolors.OffsetNorm
self.normclass = mcolors.PiecewiseLinearNorm
self.norm = self.normclass(vmin=-10, vcenter=-8, vmax=-2)
self.vals = np.array([-10., -9., -8., -6., -4., -2.])
self.expected = np.array([0.0, 0.25, 0.5, 0.666667, 0.833333, 1.0])


classtest_OffsetNorm_AllPositive(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_AllPositive(BasePiecewiseLinearNorm):
def setup(self):
self.normclass = mcolors.OffsetNorm
self.normclass = mcolors.PiecewiseLinearNorm
self.norm = self.normclass(vmin=0, vcenter=3, vmax=9)
self.vals = np.array([0., 1.5, 3., 4.5, 6.0, 7.5, 9.])
self.expected = np.array([0.0, 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])


classtest_OffsetNorm_NoVs(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_NoVs(BasePiecewiseLinearNorm):
def setup(self):
self.normclass = mcolors.OffsetNorm
self.normclass = mcolors.PiecewiseLinearNorm
self.norm = self.normclass(vmin=None, vcenter=None, vmax=None)
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0])
self.expected = np.array([0., 0.16666667, 0.33333333,
Expand All@@ -289,26 +289,26 @@ def test_vmax(self):
assert_equal(self.norm.vmax, self.expected_vmax)


classtest_OffsetNorm_VminEqualsVcenter(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_VminEqualsVcenter(BasePiecewiseLinearNorm):
def setup(self):
self.normclass = mcolors.OffsetNorm
self.normclass = mcolors.PiecewiseLinearNorm
self.norm = self.normclass(vmin=-2, vcenter=-2, vmax=2)
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
self.expected = np.array([0.5, 0.625, 0.75, 0.875, 1.0])


classtest_OffsetNorm_VmaxEqualsVcenter(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_VmaxEqualsVcenter(BasePiecewiseLinearNorm):
def setup(self):
self.normclass = mcolors.OffsetNorm
self.normclass = mcolors.PiecewiseLinearNorm
self.norm = self.normclass(vmin=-2, vcenter=2, vmax=2)
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
self.expected = np.array([0.0, 0.125, 0.25, 0.375, 0.5])


classtest_OffsetNorm_VsAllEqual(BaseOffsetNorm):
classtest_PiecewiseLinearNorm_VsAllEqual(BasePiecewiseLinearNorm):
def setup(self):
self.v = 10
self.normclass = mcolors.OffsetNorm
self.normclass = mcolors.PiecewiseLinearNorm
self.norm = self.normclass(vmin=self.v, vcenter=self.v, vmax=self.v)
self.vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
self.expected = np.array([0.0, 0.0, 0.0, 0.0, 0.0])
Expand All@@ -321,28 +321,28 @@ def test_inverse(self):
)


classtest_OffsetNorm_Errors(object):
classtest_PiecewiseLinearNorm_Errors(object):
def setup(self):
self.vals = np.arange(50)

@raises(ValueError)
def test_VminGTVcenter(self):
norm = mcolors.OffsetNorm(vmin=10, vcenter=0, vmax=20)
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=0, vmax=20)
norm(self.vals)

@raises(ValueError)
def test_VminGTVmax(self):
norm = mcolors.OffsetNorm(vmin=10, vcenter=0, vmax=5)
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=0, vmax=5)
norm(self.vals)

@raises(ValueError)
def test_VcenterGTVmax(self):
norm = mcolors.OffsetNorm(vmin=10, vcenter=25, vmax=20)
norm = mcolors.PiecewiseLinearNorm(vmin=10, vcenter=25, vmax=20)
norm(self.vals)

@raises(ValueError)
def test_premature_scaling(self):
norm = mcolors.OffsetNorm()
norm = mcolors.PiecewiseLinearNorm()
norm.inverse(np.array([0.1, 0.5, 0.9]))


Expand All@@ -355,7 +355,7 @@ def test_offset_norm_img():

fig, (ax1, ax2) = plt.subplots(ncols=2)
cmap = plt.cm.coolwarm
norm = mcolors.OffsetNorm(vmin=-2, vcenter=0, vmax=7)
norm = mcolors.PiecewiseLinearNorm(vmin=-2, vcenter=0, vmax=7)

img1 = ax1.imshow(Z, cmap=cmap, norm=None)
cbar1 = fig.colorbar(img1, ax=ax1)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp