Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ def add_lines(self, levels, colors, linewidths, erase=True):

def _ticker(self):
'''
Return two sequences: ticks (colorbar data locations)
and ticklabels (strings).
Return the sequence of ticks (colorbar data locations),
ticklabels (strings), and the corresponding offset string.
'''
locator = self.locator
formatter = self.formatter
Expand Down Expand Up @@ -653,6 +653,9 @@ def _process_values(self, b=None):
self._values = v
return
else:
self.norm.vmin, self.norm.vmax = mtrans.nonsingular(self.norm.vmin,
self.norm.vmax,
expander=0.1)
if not self.norm.scaled():
self.norm.vmin = 0
self.norm.vmax = 1
Expand Down Expand Up @@ -817,24 +820,21 @@ def _locate(self, x):
# as to make the interpolation more accurate.
b = self.norm(self._boundaries, clip=False).filled()
xn = self.norm(x, clip=False).filled()

# The rest is linear interpolation with extrapolation at ends.
y = self._y
N = len(b)
ii = np.searchsorted(b, xn)
i0 = ii - 1
itop = (ii == N)
itop = (ii == len(b))
ibot = (ii == 0)
i0[itop] -= 1
ii[itop] -= 1
i0[ibot] += 1
ii[ibot] += 1

#db = b[ii] - b[i0]
db = np.take(b, ii) - np.take(b, i0)
#dy = y[ii] - y[i0]
y = self._y
dy = np.take(y, ii) - np.take(y, i0)
z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db

return z

def set_alpha(self, alpha):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ def test_gridspec_make_colorbar():
plt.subplots_adjust(top=0.95, right=0.95, bottom=0.2, hspace=0.25)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing line here (and maybe under it too).


@image_comparison(baseline_images=['colorbar_single_scatter'],
extensions=['png'], remove_text=True,
savefig_kwarg={'dpi': 40})
def test_colorbar_single_scatter():
# Issue #2642: if a path collection has only one entry,
# the norm scaling within the colorbar must ensure a
# finite range, otherwise a zero denominator will occur in _locate.
plt.figure()
x = np.arange(4)
y = x.copy()
z = np.ma.masked_greater(np.arange(50, 54), 50)
cmap = plt.get_cmap('jet', 16)
cs = plt.scatter(x, y, z, c=z, cmap=cmap)
plt.colorbar(cs)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)