Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Don't clip colorbar dividers#23549

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 2 commits intomatplotlib:mainfromQuLogic:colorbar-dividers
Aug 9, 2022

Conversation

QuLogic
Copy link
Member

PR Summary

They are sometimes right on the edge of theAxes, and the last (or possibly first) don't get drawn due to clipping. Because the divider line width is the same as theAxes frame line width, we don't have to worry about it going outside when unclipped.

Fixes#22864

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

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

@QuLogicQuLogic added this to thev3.5.3 milestoneAug 4, 2022
@jklymak
Copy link
Member

I think we can zoom in on colorbar axes now, though, and we can certainly set the x/ylimits. Won't these now dangle in space if we do that?

@QuLogic
Copy link
MemberAuthor

I was thinking that, but when I tried it with the original example, I was unable to pan or zoom the colorbar. Did it break, or is the test not sufficiently set up to allow it?

@greglucas
Copy link
Contributor

I don't see these dangling in space if I test the original example with this...

importmatplotlibasmplimportnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlib.colorsimportfrom_levels_and_colorsmy_cmap=mpl.cm.viridisbounds=np.arange(10)nb_colors=len(bounds)+1colors=my_cmap(np.linspace(100,255,nb_colors).astype(int))my_cmap,my_norm=from_levels_and_colors(bounds,colors,extend='both')plt.figure(figsize=(5,1))ax=plt.subplot(111)cbar=mpl.colorbar.ColorbarBase(ax,cmap=my_cmap,norm=my_norm,orientation='horizontal',drawedges=True)cbar.ax.set_xlim(2,10)cbar.ax.set_navigate(True)plt.subplots_adjust(left=0.05,bottom=0.4,right=0.95,top=0.9)plt.show()

Because it is aBoundaryNorm we disable interaction:

# Don't navigate on any of these types of mappables
if (isinstance(self.norm, (colors.BoundaryNorm,colors.NoNorm))or
isinstance(self.mappable,contour.ContourSet)):
self.ax.set_navigate(False)

Manually enabling interaction moves the colors, but not the boundary lines, so those will not move around either apparently?

@QuLogic
Copy link
MemberAuthor

Going back to what pan/zoom on the Colorbar means, it moves the norm limits, and then moves the axis to match, so the colours and the dividersnever move.

Callingset_xlim can break things though:
image

They are sometimes right on the edge of the Axes, and the last (orpossibly first) don't get drawn due to clipping. Because the dividerline width is the same as the Axes frame line width, we don't have toworry about it going outside when unclipped.Fixesmatplotlib#22864
In this case, place dividers at the same place internally, but thenalways place a divider at the Axes limits (when there's an extendtriangle there).
@QuLogic
Copy link
MemberAuthor

This now tests withset_xlim as well as the other vertical orientation. It should produce a divider at the right places now even when the limits have been changed.

@tacaswelltacaswell merged commit8a495e9 intomatplotlib:mainAug 9, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestAug 9, 2022
@QuLogicQuLogic deleted the colorbar-dividers branchAugust 9, 2022 20:08
tacaswell added a commit that referenced this pull requestAug 9, 2022
…549-on-v3.5.xBackport PR#23549 on branch v3.5.x (Don't clip colorbar dividers)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@oscargusoscargusoscargus approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.5.3
Development

Successfully merging this pull request may close these issues.

[Bug]: Colorbar with drawedges=True and extend='both' does not draw edges at extremities
5 participants
@QuLogic@jklymak@greglucas@oscargus@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp