From 6a70bebce3ed846c0c89aa1f2d803db1def22e51 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 18 Apr 2020 19:59:09 +0200 Subject: [PATCH] Make all parameters of ColorbarBase, except `ax`, keyword-only. This is consistent with Colorbar. Moreover, this will make it possibly to ultimately merge Colorbar into ColorbarBase -- currently, they only differ by the fact that a ColorbarBase doesn't have an associated ScalarMappable, but we can just construct an empty ScalarMappable in that case (this is already what we document as recommended approach to construct colorbars not attached to an artist -- `fig.colorbar(ScalarMappable(norm=..., cmap=...))`. Right now this merging is *nearly* possible except for the fact that the constructors' signatures are a pain to combine. --- doc/api/api_changes_3.3/deprecations.rst | 5 +++++ lib/matplotlib/colorbar.py | 1 + lib/matplotlib/tests/test_colorbar.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/api/api_changes_3.3/deprecations.rst b/doc/api/api_changes_3.3/deprecations.rst index a1c40be2b6d6..adf6337deca9 100644 --- a/doc/api/api_changes_3.3/deprecations.rst +++ b/doc/api/api_changes_3.3/deprecations.rst @@ -455,3 +455,8 @@ replaced by calls to ``draw_idle()`` on the corresponding canvas. ~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``add_checker`` and ``check_update`` methods and ``update_dict`` attribute of `.ScalarMappable` are deprecated. + +``ColorbarBase`` parameters will become keyword-only +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +All parameters of ``ColorbarBase``, except for the first (*ax*), will become +keyword-only, consistently with ``Colorbar``. diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 09e7d3bd9e69..b49451e67e89 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -394,6 +394,7 @@ class ColorbarBase: n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize + @cbook._make_keyword_only("3.3", "cmap") def __init__(self, ax, cmap=None, norm=None, alpha=None, diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index 61b3efa3d3de..2a234cf7c0e9 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -226,7 +226,7 @@ def test_remove_from_figure(use_gridspec): def test_colorbarbase(): # smoke test from #3805 ax = plt.gca() - ColorbarBase(ax, plt.cm.bone) + ColorbarBase(ax, cmap=plt.cm.bone) @image_comparison(['colorbar_closed_patch'], remove_text=True)