FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't clip colorbar dividers by QuLogic · Pull Request #23549 · matplotlib/matplotlib · GitHub

Repository navigation

Don't clip colorbar dividers - #23549

Merged
tacaswell merged 2 commits into
matplotlib:mainfrom
QuLogic:colorbar-dividers
Aug 9, 2022
Merged

tacaswell merged 2 commits into
matplotlib:mainfrom
QuLogic:colorbar-dividers

Conversation

QuLogic commented Aug 4, 2022

Copy link
Copy Markdown
Member

PR Summary

They are sometimes right on the edge of the Axes, and the last (or possibly first) don't get drawn due to clipping. Because the divider line width is the same as the Axes 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 (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

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

QuLogic added this to the v3.5.3 milestone Aug 4, 2022

jklymak commented Aug 4, 2022

Copy link
Copy Markdown
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 commented Aug 4, 2022

Copy link
Copy Markdown
Member Author

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?

Copy link
Copy Markdown
Contributor

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

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt  
from matplotlib.colors import from_levels_and_colors

my_cmap = mpl.cm.viridis
bounds = np.arange(10)
nb_colors = len(bounds) + 1
colors = 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 a BoundaryNorm 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 commented Aug 8, 2022

Copy link
Copy Markdown
Member Author

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 dividers never move.

Calling set_xlim can break things though:

QuLogic added 2 commits August 9, 2022 00:26
They are sometimes right on the edge of the Axes, and the last (or
possibly first) don't get drawn due to clipping. Because the divider
line width is the same as the Axes frame line width, we don't have to
worry about it going outside when unclipped.

Fixes matplotlib#22864
In this case, place dividers at the same place internally, but then
always place a divider at the Axes limits (when there's an extend
triangle there).
QuLogic force-pushed the colorbar-dividers branch from 298a23f to 930bd2f Compare August 9, 2022 05:20

QuLogic commented Aug 9, 2022

Copy link
Copy Markdown
Member Author

This now tests with set_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.

tacaswell merged commit 8a495e9 into matplotlib:main Aug 9, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Aug 9, 2022
QuLogic deleted the colorbar-dividers branch August 9, 2022 20:08
tacaswell added a commit that referenced this pull request Aug 9, 2022
…549-on-v3.5.x

Backport PR #23549 on branch v3.5.x (Don't clip colorbar dividers)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

[Bug]: Colorbar with drawedges=True and extend='both' does not draw edges at extremities

5 participants


Back | FazBrowse Home | New Git URL