From 961742ce5f13fa64f083328bbca00b474481850d Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 7 Nov 2018 18:36:03 +0100 Subject: [PATCH] Make colorbars constructible with dataless ScalarMappables. This allows creating "bare" colorbars with the one-liner fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap)) --- lib/matplotlib/colorbar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index cd06617ad140..63d7efb2758a 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -1069,7 +1069,8 @@ class Colorbar(ColorbarBase): def __init__(self, ax, mappable, **kw): # Ensure the given mappable's norm has appropriate vmin and vmax set # even if mappable.draw has not yet been called. - mappable.autoscale_None() + if mappable.get_array() is not None: + mappable.autoscale_None() self.mappable = mappable kw['cmap'] = cmap = mappable.cmap