Repository navigation
Description
When plotting time sequenced data, using matplotlib.dates.MinuteLocator(interval=1) to set the x-axis ticks results in a Runtime Error. If i keep the number of ticks < 1000, the code executes as expected.
Code for reproduction
import matplotlib as mpl
import matplotlib.pyplot as plt
import datetime
num_list=[]
date_list=[]
#Create List of Datetime Objects to Plot on X Axis
start = datetime.datetime(2017 , 2, 15)
end = datetime.datetime(2017, 2, 15, 15, 10, 0)
step=datetime.timedelta(minutes=1)
while start < end:
date_list.append(start)
start+=step
#Create List of Numbers to Plot on Y Axis
num=0
lastnum=len(date_list)
while num < lastnum:
num_list.append(num)
num+=1
locator = mpl.dates.MinuteLocator(interval=1)
fig, (ax1,ax2) = plt.subplots(2)
ax1.plot_date(date_list,num_list,'b.')
ax2.plot_date(date_list,num_list,'r.')
plt.gca().xaxis.set_major_locator(locator)
plt.show()Actual outcome
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 280, in resize
self.show()
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 351, in draw
FigureCanvasAgg.draw(self)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 464, in draw
self.figure.draw(self.renderer)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\figure.py", line 1143, in draw
renderer, self, dsu, self.suppressComposite)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\axes\_base.py", line 2409, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\axis.py", line 1136, in draw
ticks_to_draw = self._update_ticks(renderer)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\axis.py", line 969, in _update_ticks
tick_tups = [t for t in self.iter_ticks()]
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\axis.py", line 969, in <listcomp>
tick_tups = [t for t in self.iter_ticks()]
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\axis.py", line 912, in iter_ticks
majorLocs = self.major.locator()
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\dates.py", line 803, in __call__
return self.tick_values(dmin, dmax)
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\dates.py", line 825, in tick_values
return self.raise_if_exceeds(date2num(dates))
File "C:\Users\user****\AppData\Local\Continuum\Miniconda3\lib\site-packages\matplotlib\ticker.py", line 1305, in raise_if_exceeds
raise RuntimeError(msg)
RuntimeError: Locator attempting to generate 1000 ticks from 736374.96875 to 736375.6625: exceeds Locator.MAXTICKS
Expected outcome
I expect this to generate a plot with an x-tick every minute. In this case I am using plt.show() and manipulating the plot generated via the gui to save the interesting part.
If i change the date_list and num_list in the example code to contain 909 elements the plot is generated as I expect.
E.G:
#Create List of Datetime Objects to Plot on X Axis
start = datetime.datetime(2017 , 2, 15)
end = datetime.datetime(2017, 2, 15, 15, 9, 0)
step=datetime.timedelta(minutes=1)
while start < end:
date_list.append(start)
start+=stepIt seems that the issue lies with >=910 elements in the date_list generating >1000 x-ticks.
Matplotlib version
import matplotlib
matplotlib.version
'2.0.0'
import platform
platform.python_version()
'3.4.2'
I used Miniconda to originally install Python, and used PIP to upgrade to later versions.
Activity
olpossum commentedon Feb 16, 2017
Looks like this can be fixed by increasing the MAXTICKS value
E.G.
olpossum commentedon Feb 16, 2017
Did not mean to close, will let mods decide if this qualifies as a bug still...
anntzer commentedon Feb 16, 2017
I would just drop out the use of MAXTICKS and let the program run out of memory if it tries to create to many ticks (after all that's already the case e.g. with huge images, there's no reason to do things differently here).
(The issue is actually not specific to date handling. Labeling as "easy" as it's a one-line fix, but it may require some discussion about whether dropping MAXTICKS is actually a good idea.)
patniharshit commentedon Feb 17, 2017
I would like to do this. Let me know whether to increase value of MAXTICKS or to remove it and let it run out of memory.
tacaswell commentedon Feb 17, 2017
I could have sworn we removed this check, maybe that is on master?
anntzer commentedon Feb 19, 2017
I think you're thinking of #6955, which only removes a redundant "optimization" check.
tacaswell commentedon Feb 20, 2017
Yeah, that is what I was thinking of.
mitko1994 commentedon Mar 4, 2017
I'm not sure if this is still an issue, but I cannot reproduce it with the code above. The graphs are displayed for me and there are no exceptions