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

Skip to content

Commit 24b22eb

Browse files
committed
BUG: Make nbagg work without IPython installed
1 parent 3302ea6 commit 24b22eb

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

lib/matplotlib/backends/backend_nbagg.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
from matplotlib import is_interactive
2727
from matplotlib.backends.backend_webagg_core import (FigureManagerWebAgg,
2828
FigureCanvasWebAggCore,
29-
NavigationToolbar2WebAgg)
29+
NavigationToolbar2WebAgg,
30+
TimerTornado)
3031
from matplotlib.backend_bases import (ShowBase, NavigationToolbar2,
31-
TimerBase, FigureCanvasBase)
32+
FigureCanvasBase)
3233

3334

3435
class Show(ShowBase):
@@ -185,38 +186,6 @@ def remove_comm(self, comm_id):
185186
if not socket.comm.comm_id == comm_id])
186187

187188

188-
class TimerTornado(TimerBase):
189-
def _timer_start(self):
190-
self._timer_stop()
191-
if self._single:
192-
ioloop = tornado.ioloop.IOLoop.instance()
193-
self._timer = ioloop.add_timeout(
194-
datetime.timedelta(milliseconds=self.interval),
195-
self._on_timer)
196-
else:
197-
self._timer = tornado.ioloop.PeriodicCallback(
198-
self._on_timer,
199-
self.interval)
200-
self._timer.start()
201-
202-
def _timer_stop(self):
203-
if self._timer is None:
204-
return
205-
elif self._single:
206-
ioloop = tornado.ioloop.IOLoop.instance()
207-
ioloop.remove_timeout(self._timer)
208-
else:
209-
self._timer.stop()
210-
211-
self._timer = None
212-
213-
def _timer_set_interval(self):
214-
# Only stop and restart it if the timer has already been started
215-
if self._timer is not None:
216-
self._timer_stop()
217-
self._timer_start()
218-
219-
220189
class FigureCanvasNbAgg(FigureCanvasWebAggCore):
221190
def new_timer(self, *args, **kwargs):
222191
return TimerTornado(*args, **kwargs)

lib/matplotlib/backends/backend_webagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from matplotlib.figure import Figure
4040
from matplotlib._pylab_helpers import Gcf
4141
from . import backend_webagg_core as core
42-
from .backend_nbagg import TimerTornado
42+
from .backend_webagg_core import TimerTornado
4343

4444

4545
def new_figure_manager(num, *args, **kwargs):

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,35 @@ def _send_event(self, event_type, **kwargs):
519519
payload.update(kwargs)
520520
for s in self.web_sockets:
521521
s.send_json(payload)
522+
523+
524+
class TimerTornado(backend_bases.TimerBase):
525+
def _timer_start(self):
526+
self._timer_stop()
527+
if self._single:
528+
ioloop = tornado.ioloop.IOLoop.instance()
529+
self._timer = ioloop.add_timeout(
530+
datetime.timedelta(milliseconds=self.interval),
531+
self._on_timer)
532+
else:
533+
self._timer = tornado.ioloop.PeriodicCallback(
534+
self._on_timer,
535+
self.interval)
536+
self._timer.start()
537+
538+
def _timer_stop(self):
539+
if self._timer is None:
540+
return
541+
elif self._single:
542+
ioloop = tornado.ioloop.IOLoop.instance()
543+
ioloop.remove_timeout(self._timer)
544+
else:
545+
self._timer.stop()
546+
547+
self._timer = None
548+
549+
def _timer_set_interval(self):
550+
# Only stop and restart it if the timer has already been started
551+
if self._timer is not None:
552+
self._timer_stop()
553+
self._timer_start()

0 commit comments

Comments
 (0)