8000 Dataless colorbars break when updated · Issue #13963 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Dataless colorbars break when updated #13963
Closed
@anntzer

Description

@anntzer

#13171 documented how to construct a colorbar "without an associated artist", via fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax). It is also possible e.g. to update the colorbar via

sm = ScalarMappable(norm=norm, cmap=cmap)
fig.colorbar(sm)
<...>
sm.set_cmap("plasma")

(Although this is only documented in master, the recipe has existed for a while.)

But this got broken by #13234: one now gets

Traceback (most recent call last):
  File "lib/matplotlib/cbook/__init__.py", line 214, in process
    func(*args, **kwargs)
  File "lib/matplotlib/colorbar.py", line 1189, in on_mappable_changed
    self.update_normal(mappable)
  File "lib/matplotlib/colorbar.py", line 1230, in update_normal
    self.set_alpha(mappable.get_alpha())
AttributeError: 'ScalarMappable' object has no attribute 'get_alpha'

Indeed, the ScalarMappable class does not define get_alpha(). I think the solutions are either to make Colorbar.update_normal first check for whether such a method exists, or to add a dummy get_alpha() (always returning 1) to ScalarMappable.

Allowing myself to label as release critical (as a regression) but feel free to relabel if you disagree.


mpl master, arch linux, py3.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: color/colorbar

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0