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

Skip to content

Commit 0e46eee

Browse files
committed
ENH: Make the ability to resample interpolated colormaps public
1 parent 2da3401 commit 0e46eee

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Make the resample method on `.Colormap` instances public
2+
--------------------------------------------------------
3+
4+
On `.LinearSegmentedColormap` and `.ListedColormap` the previously private
5+
``_resample`` method is made public. This method will create and return a new
6+
`.Colormap` instance with the specified lookup table size.

lib/matplotlib/cm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def get_cmap(name=None, lut=None):
269269
if lut is None:
270270
return _colormaps[name]
271271
else:
272-
return _colormaps[name]._resample(lut)
272+
return _colormaps[name].resample(lut)
273273

274274

275275
def unregister_cmap(name):

lib/matplotlib/colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ def is_gray(self):
854854
return (np.all(self._lut[:, 0] == self._lut[:, 1]) and
855855
np.all(self._lut[:, 0] == self._lut[:, 2]))
856856

857-
def _resample(self, lutsize):
857+
def resample(self, lutsize):
858858
"""Return a new colormap with *lutsize* entries."""
859859
raise NotImplementedError()
860860

@@ -1050,7 +1050,7 @@ def from_list(name, colors, N=256, gamma=1.0):
10501050

10511051
return LinearSegmentedColormap(name, cdict, N, gamma)
10521052

1053-
def _resample(self, lutsize):
1053+
def resample(self, lutsize):
10541054
"""Return a new colormap with *lutsize* entries."""
10551055
new_cmap = LinearSegmentedColormap(self.name, self._segmentdata,
10561056
lutsize)
@@ -1154,7 +1154,7 @@ def _init(self):
11541154
self._isinit = True
11551155
self._set_extremes()
11561156

1157-
def _resample(self, lutsize):
1157+
def resample(self, lutsize):
11581158
"""Return a new colormap with *lutsize* entries."""
11591159
colors = self(np.linspace(0, 1, lutsize))
11601160
new_cmap = ListedColormap(colors, name=self.name)

lib/matplotlib/tests/test_colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_create_lookup_table(N, result):
3131

3232
def test_resample():
3333
"""
34-
GitHub issue #6025 pointed to incorrect ListedColormap._resample;
34+
GitHub issue #6025 pointed to incorrect ListedColormap.resample;
3535
here we test the method for LinearSegmentedColormap as well.
3636
"""
3737
n = 101
@@ -47,8 +47,8 @@ def test_resample():
4747
cmap.set_under('r')
4848
cmap.set_over('g')
4949
cmap.set_bad('b')
50-
lsc3 = lsc._resample(3)
51-
lc3 = lc._resample(3)
50+
lsc3 = lsc.resample(3)
51+
lc3 = lc.resample(3)
5252
expected = np.array([[0.0, 0.2, 1.0, 0.7],
5353
[0.5, 0.2, 0.5, 0.7],
5454
[1.0, 0.2, 0.0, 0.7]], float)

0 commit comments

Comments
 (0)