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

Fixed colorbar bug when yscaled length is 1 by Andes0113 · Pull Request #23984 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 9 additions & 4 deletions lib/matplotlib/colorbar.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,10 @@ def _proportional_y(self):
if (isinstance(self.norm, colors.BoundaryNorm) or
self.boundaries is not None):
y = (self._boundaries - self._boundaries[self._inside][0])
y = y / (self._boundaries[self._inside][-1] -
self._boundaries[self._inside][0])
if (self._boundaries[self._inside][-1]
!= self._boundaries[self._inside][0]):
y = y / (self._boundaries[self._inside][-1] -
self._boundaries[self._inside][0])
# need yscaled the same as the axes scale to get
# the extend lengths.
if self.spacing == 'uniform':
Expand All @@ -1243,10 +1245,13 @@ def _proportional_y(self):
yscaled = np.ma.filled(norm(yscaled), np.nan)
# make the lower and upper extend lengths proportional to the lengths
# of the first and last boundary spacing (if extendfrac='auto'):
automin = yscaled[1] - yscaled[0]
automax = yscaled[-1] - yscaled[-2]
extendlength = [0, 0]
if self._extend_lower() or self._extend_upper():
automin = yscaled[0]
automax = yscaled[0]
if len(yscaled) > 1:
automin = yscaled[1] - yscaled[0]
automax = yscaled[-1] - yscaled[-2]
extendlength = self._get_extension_lengths(
self.extendfrac, automin, automax, default=0.05)
return y, extendlength
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ def test_contour_colorbar():
fig.colorbar(CS, orientation='vertical')


def test_contour_uniformfield_colorbar():
# Smoke test for gh#23817
fig, ax = plt.subplots()
with pytest.warns(Warning) as record:
cs = ax.contour([[1, 1], [1, 1]])
assert len(record) == 1
Comment thread
oscargus marked this conversation as resolved.
fig.colorbar(cs, ax=ax)


@image_comparison(['cbar_with_subplots_adjust.png'], remove_text=True,
savefig_kwarg={'dpi': 40})
def test_gridspec_make_colorbar():
Expand Down

Back | FazBrowse Home | New Git URL