8000 FIX: Reset CL counter for each new figure · matplotlib/matplotlib@c0d2ed1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c0d2ed1

Browse files
committed
FIX: Reset CL counter for each new figure
1 parent 9ec4b95 commit c0d2ed1

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

lib/matplotlib/_layoutbox.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def get_renderer(fig):
4444

4545
return renderer
4646

47+
len_seq = 6 # number of digints in unique id. See seq_id below...
4748

4849
class LayoutBox(object):
4950
"""
@@ -354,7 +355,9 @@ def _is_subplotspec_layoutbox(self):
354355
Helper to check if this layoutbox is the layoutbox of a
355356
subplotspec
356357
'''
357-
name = (self.name).split('.')[-1][:-3]
358+
global len_seq
359+
360+
name = (self.name).split('.')[-1][:-len_seq]
358361
if name == 'ss':
359362
return True
360363
return False
@@ -364,7 +367,9 @@ def _is_gridspec_layoutbox(self):
364367
Helper to check if this layoutbox is the layoutbox of a
365368
gridspec
366369
'''
367-
name = (self.name).split('.')[-1][:-3]
370+
global len_seq
371+
372+
name = (self.name).split('.')[-1][:-len_seq]
368373
if name == 'gridspec':
369374
return True
370375
return False
@@ -645,8 +650,10 @@ def seq_id():
645650
'''
646651

647652
global _layoutboxobjnum
653+
global len_seq
648654

649-
return ('%03d' % (next(_layoutboxobjnum)))
655+
fstr = '%0{}d'.format(len_seq)
656+
return (fstr%(next(_layoutboxobjnum)))
650657

651658

652659
def print_children(lb):

lib/matplotlib/animation.py

Lines changed: 12 additions & 32 deletions
Original f 8000 ile line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
from pathlib import Path
2727
import platform
28+
import shutil
2829
import subprocess
2930
import sys
3031
from tempfile import TemporaryDirectory
@@ -408,27 +409,9 @@ def bin_path(cls):
408409
@classmethod
409410
def isAvailable(cls):
410411
'''
411-
Check to see if a MovieWriter subclass is actually available by
412-
running the commandline tool.
412+
Check to see if a MovieWriter subclass is actually available.
413413
'''
414-
bin_path = cls.bin_path()
415-
if not bin_path:
416-
return False
417-
try:
418-
p = subprocess.Popen(
419-
bin_path,
420-
shell=False,
421-
stdout=subprocess.PIPE,
422-
stderr=subprocess.PIPE,
423-
creationflags=subprocess_creation_flags)
424-
return cls._handle_subprocess(p)
425-
except OSError:
426-
return False
427-
428-
@classmethod
429-
def _handle_subprocess(cls, process):
430-
process.communicate()
431-
return True
414+
return shutil.which(cls.bin_path()) is not None
432415

433416

434417
class FileMovieWriter(MovieWriter):
@@ -633,13 +616,14 @@ def output_args(self):
633616
return args + ['-y', self.outfile]
634617

635618
@classmethod
636-
def _handle_subprocess(cls, process):
637-
_, err = process.communicate()
638-
# Ubuntu 12.04 ships a broken ffmpeg binary which we shouldn't use
639-
# NOTE : when removed, remove the same method in AVConvBase.
640-
if 'Libav' in err.decode():
641-
return False
642-
return True
619+
def isAvailable(cls):
620+
return (
621+
super().isAvailable()
622+
# Ubuntu 12.04 ships a broken ffmpeg binary which we shouldn't use.
623+
# NOTE: when removed, remove the same method in AVConvBase.
624+
and b'LibAv' not in subprocess.run(
625+
[cls.bin_path()], creationflags=subprocess_creation_flags,
626+
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE).stderr)
643627

644628

645629
# Combine FFMpeg options with pipe-based writing
@@ -697,9 +681,7 @@ class AVConvBase(FFMpegBase):
697681
args_key = 'animation.avconv_args'
698682

699683
# NOTE : should be removed when the same method is removed in FFMpegBase.
700-
@classmethod
701-
def _handle_subprocess(cls, process):
702-
return MovieWriter._handle_subprocess(process)
684+
isAvailable = classmethod(MovieWriter.isAvailable.__func__)
703685

704686

705687
# Combine AVConv options with pipe-based writing
@@ -772,8 +754,6 @@ def isAvailable(cls):
772754
cls._init_from_registry()
773755
return super().isAvailable()
774756

775-
ImageMagickBase._init_from_registry()
776-
777757

778758
# Note: the base classes need to be in that order to get
779759
# isAvailable() from ImageMagickBase called and not the

0 commit comments

Comments
 (0)
0