-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't clip colorbar dividers #23549
Conversation
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? |
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? |
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 matplotlib/lib/matplotlib/colorbar.py Lines 474 to 477 in 02e93e2
Manually enabling interaction moves the colors, but not the boundary lines, so those will not move around either apparently? |
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).
298a23f
to
930bd2f
Compare
This now tests with |
…549-on-v3.5.x Backport PR #23549 on branch v3.5.x (Don't clip colorbar dividers)
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 theAxes
frame line width, we don't have to worry about it going outside when unclipped.Fixes #22864
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).