Skip to content
Closed
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
6 changes: 3 additions & 3 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,10 +1614,10 @@ def __call__(self):
def tick_values(self, vmin, vmax):
if vmax < vmin:
vmin, vmax = vmax, vmin
vmin = self._base.ge(vmin)
base = self._base.get_base()
n = (vmax - vmin + 0.001 * base) // base
locs = vmin - base + np.arange(n + 3) * base
nmin = round(self._base.ge(vmin) / base)
nmax = round(self._base.le(vmax) / base)
locs = np.arange(nmin, nmax + 1) * base
Copy link
Member

Choose a reason for hiding this comment

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

Why can't this code be simplified to: `np.arange(vmin, vmax + base, base)? Floating point errors?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry… np.arange(self._base.ge(vmin), vmax + base, base) would be the correct solution.

Copy link
Contributor

@anntzer anntzer Sep 19, 2016

Choose a reason for hiding this comment

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

Your proposal can include a value that's above vmax (eg. vmin=.5, vmax=2.5, base=1 will return [1, 2, 3]). I guess another solution that's safe against floating point errors is
np.arange(self._base.ge(vmin), self._base.le(vmax) + base / 2, base)
(the + base / 2 should take care of any fpe).

Copy link
Member

Choose a reason for hiding this comment

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

Yep: I am just concern about the tests that don't make sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I had a quick look and am pretty sure that the test values are wrong (i.e. they were picked to match the previous algorithm, which returns out of bounds values; they should be changed to match the new algorithm).

return self.raise_if_exceeds(locs)

def view_limits(self, dmin, dmax):
Expand Down