Skip to content

MNT: privatize colorbar attr #21933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2022

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Dec 12, 2021

PR Summary

In partial response to #21932: we deprecated filled from clashing with the ContourSet mappable, but none of the other mappables can change filled, so we have basically made the argument useless. This PR simply deprecates the useless kwarg.

The filled kwarg doesn't directly do anything and filling is completely controlled by the mappable.

OTOH, maybe we want to reinstate the ability of filled to fill ContourSets that are not filled - that is what #21932 would like?

Also deprecates draw_all as a public method. This doesn't draw anything, and its is not used as public API:

Other potential attributes to make read-only:

  • values
  • boundaries
  • solids
  • solids_patches
  • lines
  • orientation
  • cmap
  • norm
  • alpha
  • outline

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

The *filled* kwarg doesn't directly do anything and filling is
completely controlled by the mappable.

OTOH, maybe we want to reinstate the ability of *filled* to fill
contours?
@jklymak jklymak requested a review from anntzer December 12, 2021 08:30
@jklymak
Copy link
Member Author

jklymak commented Dec 12, 2021

@anntzer you did some to the previous work here.

@anntzer
Copy link
Contributor

anntzer commented Dec 12, 2021

OTOH, maybe we want to reinstate the ability of filled to fill ContourSets that are not filled - that is what #21932 would like?

I guess I'm not really sure what a filled colorbar for a nonfilled contourset would look like, as one specifies colors for intervals and the other specifies colors for edges?

I'm OK with the change here (modulo deprecation note, yada yada), although it's unclear whether we'll want to restore filled as a separate parameter later (I'll defer to your judgment on that), in which case that would probably partially undo this PR?

@jklymak
Copy link
Member Author

jklymak commented Dec 12, 2021

Yes we should definitely decide if we want to reinstate the filling behaviour before releasing 3.6. I'm mildly against, otoh line-only colorbars are a bit hard to read so I can understand why folks want them filled.

@timhoffm
Copy link
Member

timhoffm commented Dec 12, 2021

I agree that filled should be private. Modulo deprecation ...

RE reinstantiate: Is it the task of the colorbar to decide that or should the ScalarMappable define how it would like its colorbar to be rendered?

@jklymak
Copy link
Member Author

jklymak commented Dec 13, 2021

Maybe @greglucas has some thoughts?

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues with this deprecation from me. Just a few minor comments that are tangential to this PR and could be addressed in a follow-up, like considering what we actually want public/private API of the Colorbar to look like. I'm just putting these comments down here so I don't forget about them later, but I don't think they are necessary for this PR.

  • Do we need update_ticks() at all? It says it shouldn't be used by the public, and It is 4 lines that could be put into the _draw_all method since that is the only place it is ever called.
  • Should update_normal() be a private _update_normal() instead? I think this was needed by users when the norm information wasn't automatically updated/propagated to the Colorbar, but now this is taken care of by being attached to the norm's callback So, it is really an internal helper instead of public API.

if isinstance(self.mappable, contour.ContourSet):
CS = self.mappable
if not CS.filled:
self.add_lines(CS)
self.stale = True

@_api.deprecated("3.6", alternative="fig.draw_without_rendering()")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does draw_without_rendering() actually hit this path? I guess so when the axes this colorbar is attached to gets called? But, it isn't obvious to me.

"""
self._draw_all()

def _draw_all(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to _update_parameters() or something like that instead? A quick search shows that the only other draw_all() is in pyplot to update all stale figures, which is very different from this draw_all.

As an aside, I'm wondering if this information should actually be in a draw(self, renderer) method instead (it looks like Colorbar doesn't have a draw() currently), that can then call self.ax.draw() after these updates.

@jklymak
Copy link
Member Author

jklymak commented Jan 20, 2022

This has two approvals, so I'll self merge....

@jklymak jklymak merged commit 6b4e640 into matplotlib:main Jan 20, 2022
@jklymak jklymak deleted the mnt-privatize-colorbar-attr branch January 20, 2022 08:31
@oscargus oscargus added this to the v3.6.0 milestone Aug 1, 2022
@ksunden ksunden mentioned this pull request Mar 31, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants