Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue 807 auto minor locator #961

Merged
merged 1 commit into from

2 participants

Benjamin Root John Hunter
Benjamin Root
Collaborator

Possible bugfix for issue #807.

John Hunter
Owner

I can duplicate the error in issue 807, but when I run with your patch, although it prevents the crash, I still get lots of warnings:

msierig@pinchiepie:~> python test.py
/home/msierig/dev/lib/python2.7/site-packages/matplotlib/ticker.py:1557: RuntimeWarning: divide by zero encountered in double_scalars
  tmin = np.ceil((vmin - t0) / minorstep) * minorstep
/home/msierig/dev/lib/python2.7/site-packages/matplotlib/ticker.py:1557: RuntimeWarning: invalid value encountered in double_scalars
  tmin = np.ceil((vmin - t0) / minorstep) * minorstep
/home/msierig/dev/lib/python2.7/site-packages/matplotlib/ticker.py:1558: RuntimeWarning: divide by zero encountered in double_scalars
  tmax = np.floor((vmax - t0) / minorstep) * minorstep
/home/msierig/dev/lib/python2.7/site-packages/matplotlib/ticker.py:1558: RuntimeWarning: invalid value encountered in double_scalars
  tmax = np.floor((vmax - t0) / minorstep) * minorstep
John Hunter
Owner

I'm going to merge this now because it is an improvement over what we have and it fixes a legitimate bug. There may be better solutions out there but we can clean later. I need to get 1.1.1 out today for the debian release freeze so I am going to include this.

John Hunter jdh2358 merged commit 7e47149 into from
Benjamin Root WeatherGod deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 13 deletions.
  1. +23 −13 lib/matplotlib/ticker.py
36 lib/matplotlib/ticker.py
View
@@ -1527,15 +1527,22 @@ def __call__(self):
try:
majorstep = majorlocs[1] - majorlocs[0]
except IndexError:
- raise ValueError('Need at least two major ticks to find minor '
- 'tick locations')
+ # Need at least two major ticks to find minor tick locations
+ # TODO: Figure out a way to still be able to display minor
+ # ticks without two major ticks visible. For now, just display
+ # no ticks at all.
+ majorstep = 0
if self.ndivs is None:
- x = int(round(10 ** (np.log10(majorstep) % 1)))
- if x in [1, 5, 10]:
- ndivs = 5
- else:
- ndivs = 4
+ if majorstep == 0 :
+ # TODO: Need a better way to figure out ndivs
+ ndivs = 1
+ else :
+ x = int(round(10 ** (np.log10(majorstep) % 1)))
+ if x in [1, 5, 10]:
+ ndivs = 5
+ else:
+ ndivs = 4
else:
ndivs = self.ndivs
@@ -1545,12 +1552,15 @@ def __call__(self):
if vmin > vmax:
vmin,vmax = vmax,vmin
- t0 = majorlocs[0]
- tmin = np.ceil((vmin - t0) / minorstep) * minorstep
- tmax = np.floor((vmax - t0) / minorstep) * minorstep
- locs = np.arange(tmin, tmax, minorstep) + t0
- cond = np.abs((locs - t0) % majorstep) > minorstep/10.0
- locs = locs.compress(cond)
+ if len(majorlocs) > 0:
+ t0 = majorlocs[0]
+ tmin = np.ceil((vmin - t0) / minorstep) * minorstep
+ tmax = np.floor((vmax - t0) / minorstep) * minorstep
+ locs = np.arange(tmin, tmax, minorstep) + t0
+ cond = np.abs((locs - t0) % majorstep) > minorstep/10.0
+ locs = locs.compress(cond)
+ else:
+ locs = []
return self.raise_if_exceeds(np.array(locs))
Something went wrong with that request. Please try again.