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

Skip to content

Commit 8425637

Browse files
committed
Add support for bivariate in scatter
1 parent 575a244 commit 8425637

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,6 +3979,17 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
39793979
else:
39803980
try:
39813981
c_array = np.asanyarray(c, dtype=float)
3982+
if c_array.ndim > 1:
3983+
if cmap is None:
3984+
cmap = mcolors.BivariateColormap()
3985+
if norm is None:
3986+
norm = mcolors.BivariateNorm()
3987+
c_array = norm(c_array)
3988+
c_array[0] = c_array[0] * (cmap.N-1)
3989+
c_array[1] = c_array[1] * (cmap.N-1)
3990+
c_array = c_array.astype(int)
3991+
c_array = c_array[0] + cmap.N * c_array[1]
3992+
norm = mcolors.NoNorm()
39823993
if c_array.shape in xy_shape:
39833994
c = np.ma.ravel(c_array)
39843995
else:
@@ -4043,8 +4054,10 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
40434054
collection.update(kwargs)
40444055

40454056
if colors is None:
4046-
if norm is not None and not isinstance(norm, mcolors.Normalize):
4047-
msg = "'norm' must be an instance of 'mcolors.Normalize'"
4057+
isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm))
4058+
if norm is not None and not isNorm:
4059+
msg = "'norm' must be an instance of 'mcolors.Normalize' " \
4060+
"or 'mcolors.BivariateNorm'"
40484061
raise ValueError(msg)
40494062
collection.set_array(np.asarray(c))
40504063
collection.set_cmap(cmap)

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def reversed(self, name=None):
859859

860860

861861
class BivariateColormap(Colormap):
862-
def __init__(self, name, N=256):
862+
def __init__(self, name='bivariate', N=256):
863863
Colormap.__init__(self, name, N)
864864

865865
def _init(self):

0 commit comments

Comments
 (0)