Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0022de2

Browse files
committed
raise if num ticks exceeds some threshold to address sf bug 2715172
svn path=/trunk/matplotlib/; revision=7676
1 parent e4a5ddf commit 0022de2

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

lib/matplotlib/dates.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ def __call__(self):
522522

523523
self.rule.set(dtstart=start, until=stop)
524524
dates = self.rule.between(dmin, dmax, True)
525+
if len(dates)>=ticker.Locator.MAXTICKS:
526+
raise RuntimeError('RRuleLocator attempting to generate %d ticks from %s to %s: exceeds matplotlib.ticker.Locator.MAXTICKS'%(len(dates), dates[0], dates[-1]))
525527
return date2num(dates)
526528

527529
def _get_unit(self):

lib/matplotlib/tests/test_dates.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
import numpy as np
3-
from matplotlib.testing.decorators import image_comparison
3+
from matplotlib.testing.decorators import image_comparison, knownfailureif
44
import matplotlib.pyplot as plt
55

66
@image_comparison(baseline_images=['date_empty'])
@@ -66,7 +66,10 @@ def test_date_axvline():
6666
fig.autofmt_xdate()
6767
fig.savefig('date_axvline')
6868

69-
@image_comparison(baseline_images=['date_xlim_empty'])
69+
# we want to test that this method raises a RuntimeError -- what is
70+
# the rightway to do this in the current framework
71+
@knownfailureif(True)
72+
#@image_comparison(baseline_images=['date_xlim_empty'])
7073
def test_set_xlim_and_unexpected_handling():
7174
# Attempt to test SF 2715172, see
7275
# https://sourceforge.net/tracker/?func=detail&aid=2715172&group_id=80706&atid=560720
@@ -80,7 +83,7 @@ def test_set_xlim_and_unexpected_handling():
8083
ax.xaxis.set_major_locator(DayLocator())
8184
ax.xaxis.set_major_formatter(DateFormatter("%m/%d/%y, %I:%M%p"))
8285
ax.xaxis.set_minor_locator(HourLocator())
83-
if 1:
86+
if 0:
8487
# this seems to cause an ininite loop.
8588
from nose.plugins.skip import SkipTest
8689
raise SkipTest('avoiding never-ending drawing')

lib/matplotlib/ticker.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,14 @@ class Locator(TickHelper):
657657
because the locator stores references to the Axis data and view
658658
limits
659659
"""
660-
660+
661+
# some automatic tick locators can generate so many ticks they
662+
# kill the machine when you try and render them, see eg sf bug
663+
# report
664+
# https://sourceforge.net/tracker/index.php?func=detail&aid=2715172&group_id=80706&atid=560720.
665+
# This parameter is set to cause locators to raise an error if too
666+
# many ticks are generated
667+
MAXTICKS = 1000
661668
def __call__(self):
662669
'Return the locations of the ticks'
663670
raise NotImplementedError('Derived must override')

lib/matplotlib/transforms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,7 @@ def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True):
22662266
else:
22672267
vmin -= expander*abs(vmin)
22682268
vmax += expander*abs(vmax)
2269+
22692270
if swapped and not increasing:
22702271
vmin, vmax = vmax, vmin
22712272
return vmin, vmax

0 commit comments

Comments
 (0)