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

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ def set_array(self, A):
Parameters
----------
A : array-like or None
The values that are mapped to colors.
The values that are mapped to colors. If None, colormapping is
disabled.

The base class `.ScalarMappable` does not make any assumptions on
the dimensionality and shape of the value array *A*.
Expand All @@ -386,6 +387,9 @@ def get_array(self):

The base class `.ScalarMappable` does not make any assumptions on
the dimensionality and shape of the array.

Subclasses may decide per instance if they support colormapping.
Return None here in case they don't.
"""
return self._A

Expand Down
16 changes: 11 additions & 5 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,18 @@ def __init__(self, ax, mappable=None, *, cmap=None,
):

if mappable is None:
# Special case for a standalone colormap
mappable = cm.ScalarMappable(norm=norm, cmap=cmap)

# Ensure the given mappable's norm has appropriate vmin and vmax
# set even if mappable.draw has not yet been called.
if mappable.get_array() is not None:
mappable.autoscale_None()
else:
if mappable.get_array() is None:
_api.deprecated("3.5",
message="The given mappable instance "
f"{mappable!r} does not support colormapping. "
"Possibly it has explicitly specified colors.")
else:
# Ensure the given mappable's norm has appropriate vmin and
# vmax set even if mappable.draw has not yet been called.
mappable.autoscale_None()

self.mappable = mappable
cmap = mappable.cmap
Expand Down