Skip to content

Make colorbars constructible with dataless ScalarMappables. - #12767

Merged
jklymak merged 1 commit into
matplotlib:masterfrom
anntzer:scalarmappable-default-array
Nov 8, 2018
Merged

jklymak merged 1 commit into
matplotlib:masterfrom
anntzer:scalarmappable-default-array

Conversation

@anntzer

@anntzer anntzer commented Nov 7, 2018 •

Copy link
Copy Markdown
Contributor

This allows creating "bare" colorbars with the one-liner

fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap))

xref #3644 (comment)

As to the answer to the question in that comment ("What would be the implication if that is changed to self._A = []?"):

That wouldn't work because ScalarMappables need to also support cases where the color is directly set by the end user (explicit RGBA image, or explicit colors in scatter plots), in which case they mark that fact with A == None (at least initially, then A becomes the RGBA array, the whole thing looks a bit messy...).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.1 milestone Nov 7, 2018
This allows creating "bare" colorbars with the one-liner

    fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap))
@anntzer anntzer changed the title Default ScalarMappable._A to an empty array instead of None. Make colorbars constructible with dataless ScalarMappables. Nov 7, 2018
@anntzer
anntzer force-pushed the scalarmappable-default-array branch from 4ed0703 to 961742c Compare November 7, 2018 21:00
@ImportanceOfBeingErnest

Copy link
Copy Markdown
Member

I think I remember that just doing self._A = [] failed, but I didn't go further to find out why. Thanks for finding out. 😁

This is pretty useful, because it makes manual colorbar creation much more intuitive.

@jklymak
jklymak merged commit da58453 into matplotlib:master Nov 8, 2018
@anntzer
anntzer deleted the scalarmappable-default-array branch January 13, 2019 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants