8000 Add a `name` parameter to `truncate` · matplotlib/matplotlib@79bfcfb · GitHub
[go: up one dir, main page]

Skip to content

Commit 79bfcfb

Browse files
committed
Add a name parameter to truncate
reorder `join` inputs (for consistency) +doc fixes/changes
1 parent 8799485 commit 79bfcfb

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/matplotlib/colors.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,21 +589,21 @@ def reversed(self, name=None):
589589
"""
590590
raise NotImplementedError()
591591

592-
def join(self, other, name=None, frac_self=None, N=None):
592+
def join(self, other, frac_self=None, name=None, N=None):
593593
"""
594594
Join colormap `self` to `other` and return the new colormap.
595595
596596
Parameters
597597
----------
598598
other : cmap
599599
The other colormap to be joined to this one.
600-
name : str, optional
601-
The name for the reversed colormap. If it's None the
602-
name will be ``self.name + '-' + other.name``.
603600
frac_self : float in the interval ``(0.0, 1.0)``, optional
604601
The fraction of the new colormap that should be occupied
605602
by self. By default, this is ``self.N / (self.N +
606603
other.N)``.
604+
name : str, optional
605+
The name for the joined colormap. This defaults to
606+
``self.name + '+' + other.name``
607607
N : int
608608
The number of entries in the color map. The default is ``None``,
609609
in which case the number of entries is the sum of the
@@ -646,7 +646,7 @@ def join(self, other, name=None, frac_self=None, N=None):
646646

647647
__add__ = join
648648

649-
def truncate(self, minval=0.0, maxval=1.0, N=None):
649+
def truncate(self, minval=0.0, maxval=1.0, name=None, N=None):
650650
"""
651651
Truncate a colormap.
652652
@@ -655,11 +655,12 @@ def truncate(self, minval=0.0, maxval=1.0, N=None):
655655
minval : float in the interval ``(0.0, 1.0)``, optional
656656
The lower fraction of the colormap you want to truncate
657657
(default 0.0).
658-
659658
maxval : float in the interval ``(0.0, 1.0)``, optional
660659
The upper limit of the colormap you want to keep. i.e. truncate
661660
the section above this value (default 1.0).
662-
661+
name : str, optional
662+
The name for the new truncated colormap. This defaults to
663+
``"trunc({},{:.2f},{:.2f})".format(self.name, minval, maxval)``
663664
N : int
664665
The number of entries in the map. The default is *None*,
665666
in which case the same color-step density is preserved,
@@ -694,7 +695,8 @@ def truncate(self, minval=0.0, maxval=1.0, N=None):
694695
# http://stackoverflow.com/a/18926541/2121597
695696
if N is None:
696697
N = np.ceil(self.N * (maxval - minval))
697-
name = "trunc({},{:.2f},{:.2f})".format(self.name, minval, maxval)
698+
if name is None:
699+
name = "trunc({},{:.2f},{:.2f})".format(self.name, minval, maxval)
698700
return ListedColormap(self(np.linspace(minval, maxval, N)), name)
699701

700702

0 commit comments

Comments
 (0)
0