10000 Default ScalarMappable._A to an empty array instead of None. · matplotlib/matplotlib@4ed0703 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ed0703

Browse files
committed
Default ScalarMappable._A to an empty array instead of None.
This makes it unnecessary for other code to handle None, and is a useful default for creating "bare" colorbars, which can now be done with the one-liner fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap))
1 parent 4dbbd22 commit 4ed0703

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

lib/matplotlib/cm.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(self, norm=None, cmap=None):
210210
if norm is None:
211211
norm = colors.Normalize()
212212

213-
self._A = None
213+
self._A = np.array([])
214214
#: The Normalization instance of this ScalarMappable.
215215
self.norm = norm
216216
#: The Colormap instance of this ScalarMappable.
@@ -360,8 +360,6 @@ def autoscale(self):
360360
Autoscale the scalar limits on the norm instance using the
361361
current array
362362
"""
363-
if self._A is None:
364-
raise TypeError('You must first set_array for mappable')
365363
self.norm.autoscale(self._A)
366364
self.changed()
367365

@@ -370,8 +368,6 @@ def autoscale_None(self):
370368
Autoscale the scalar limits on the norm instance using the
371369
current array, changing only limits that are None
372370
"""
373-
if self._A is None:
374-
raise TypeError('You must first set_array for mappable')
375371
self.norm.autoscale_None(self._A)
376372
self.changed()
377373

0 commit comments

Comments
 (0)
0