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

Appearance settings

Commit d59bd35

Browse filesBrowse files
committed
fixes
1 parent 5dd4a6e commit d59bd35
Copy full SHA for d59bd35

File tree

Expand file treeCollapse file tree

2 files changed

+31
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-6
lines changed

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+17-6Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def __init__(self, parent, userax=True):
262262
outer_ax = parent
263263

264264
inner_ax = outer_ax.inset_axes([0, 0, 1, 1])
265-
self.__dict__ = inner_ax.__dict__
265+
self.__dict__.update(inner_ax.__dict__)
266266

267267
self.outer_ax = outer_ax
268268
self.inner_ax = inner_ax
@@ -749,6 +749,8 @@ def _get_ticker_locator_formatter(self):
749749
locator = ticker.FixedLocator(b, nbins=10)
750750
else: # most cases:
751751
if locator is None:
752+
# we haven't set the locator explicitly, so use the default
753+
# for this axis:
752754
locator = self._long_axis().get_major_locator()
753755
if minorlocator is None:
754756
minorlocator = self._long_axis().get_minor_locator()
@@ -793,8 +795,18 @@ def set_ticks(self, ticks, update_ticks=True):
793795
self.stale = True
794796

795797
def get_ticks(self, minor=False):
796-
"""Return the x ticks as a list of locations."""
797-
return self._long_axis().get_majorticklocs()
798+
"""
799+
Return the x ticks as a list of locations.
800+
801+
Parameters
802+
----------
803+
minor : boolean, default: False
804+
if True return the minor ticks.
805+
"""
806+
if minor:
807+
return self._long_axis().get_minorticklocs()
808+
else:
809+
return self._long_axis().get_majorticklocs()
798810

799811
@_api.delete_parameter("3.5", "update_ticks")
800812
def set_ticklabels(self, ticklabels, update_ticks=True):
@@ -905,8 +917,7 @@ def _process_values(self):
905917
self._boundaries = np.array(self.boundaries)
906918
return
907919

908-
# otherwise values are set from the boundaries (and probably aren't
909-
# that important)
920+
# otherwise values are set from the boundaries
910921
if isinstance(self.norm, colors.BoundaryNorm):
911922
b = self.norm.boundaries
912923
else:
@@ -916,7 +927,7 @@ def _process_values(self):
916927
# add extra boundaries if needed:
917928
if self._extend_lower():
918929
b = np.hstack((b[0] - 1, b))
919-
if self._extend_lower():
930+
if self._extend_upper():
920931
b = np.hstack((b, b[-1] + 1))
921932

922933
# transform from 0-1 to vmin-vmax:

‎lib/matplotlib/tests/test_colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colorbar.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,20 @@ def test_colorbar_get_ticks():
442442
defTicks = plt.colorbar(orientation='horizontal')
443443
np.testing.assert_allclose(defTicks.get_ticks().tolist(), levels)
444444

445+
# test normal ticks and minor ticks
446+
fig, ax = plt.subplots()
447+
x = np.arange(-3.0, 4.001)
448+
y = np.arange(-4.0, 3.001)
449+
X, Y = np.meshgrid(x, y)
450+
Z = X * Y
451+
Z = Z[:-1, :-1]
452+
pcm = ax.pcolormesh(X, Y, Z)
453+
cbar = fig.colorbar(pcm, ax=ax, extend='both',
454+
orientation='vertical')
455+
ticks = cbar.get_ticks()
456+
np.testing.assert_allclose(ticks, np.arange(-15, 16, 5))
457+
assert len(cbar.get_ticks(minor=True)) == 0
458+
445459

446460
def test_colorbar_lognorm_extension():
447461
# Test that colorbar with lognorm is extended correctly

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.