Python matplotlib.rcParams.get() Examples

The following are 30 code examples of matplotlib.rcParams.get(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.rcParams , or try the search function .
Example #1
Source File: backend_pgf.py    From Computable with MIT License 6 votes vote down vote up
def print_pgf(self, fname_or_fh, *args, **kwargs):
        """
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pgf is to be written to
        if is_string_like(fname_or_fh):
            with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
                self._print_pgf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            raise ValueError("saving pgf to a stream is not supported, " +
                             "consider using the pdf option of the pgf-backend")
        else:
            raise ValueError("filename must be a path") 
Example #2
Source File: backend_pgf.py    From Computable with MIT License 6 votes vote down vote up
def get_latex_manager():
        texcommand = get_texcommand()
        latex_header = LatexManager._build_latex_header()
        prev = LatexManagerFactory.previous_instance

        # check if the previous instance of LatexManager can be reused
        if prev and prev.latex_header == latex_header and prev.texcommand == texcommand:
            if rcParams.get("pgf.debug", False):
                print("reusing LatexManager")
            return prev
        else:
            if rcParams.get("pgf.debug", False):
                print("creating LatexManager")
            new_inst = LatexManager()
            LatexManagerFactory.previous_instance = new_inst
            return new_inst 
Example #3
Source File: backend_pgf.py    From neural-network-animation with MIT License 6 votes vote down vote up
def get_latex_manager():
        texcommand = get_texcommand()
        latex_header = LatexManager._build_latex_header()
        prev = LatexManagerFactory.previous_instance

        # check if the previous instance of LatexManager can be reused
        if prev and prev.latex_header == latex_header and prev.texcommand == texcommand:
            if rcParams.get("pgf.debug", False):
                print("reusing LatexManager")
            return prev
        else:
            if rcParams.get("pgf.debug", False):
                print("creating LatexManager")
            new_inst = LatexManager()
            LatexManagerFactory.previous_instance = new_inst
            return new_inst 
Example #4
Source File: backend_pgf.py    From Computable with MIT License 6 votes vote down vote up
def get_fontspec():
    """Build fontspec preamble from rc."""
    latex_fontspec = []
    texcommand = get_texcommand()

    if texcommand != "pdflatex":
        latex_fontspec.append(r"\usepackage{fontspec}")

    if texcommand != "pdflatex" and rcParams.get("pgf.rcfonts", True):
        # try to find fonts from rc parameters
        families = ["serif", "sans-serif", "monospace"]
        fontspecs = [r"\setmainfont{%s}", r"\setsansfont{%s}",
                     r"\setmonofont{%s}"]
        for family, fontspec in zip(families, fontspecs):
            matches = [f for f in rcParams["font." + family]
                       if f in system_fonts]
            if matches:
                latex_fontspec.append(fontspec % matches[0])
            else:
                pass  # no fonts found, fallback to LaTeX defaule

    return "\n".join(latex_fontspec) 
Example #5
Source File: backend_pgf.py    From Computable with MIT License 6 votes vote down vote up
def __init__(self, figure, fh, dummy=False):
        """
        Creates a new PGF renderer that translates any drawing instruction
        into text commands to be interpreted in a latex pgfpicture environment.

        Attributes:
        * figure: Matplotlib figure to initialize height, width and dpi from.
        * fh: File handle for the output of the drawing commands.
        """
        RendererBase.__init__(self)
        self.dpi = figure.dpi
        self.fh = fh
        self.figure = figure
        self.image_counter = 0

        # get LatexManager instance
        self.latexManager = LatexManagerFactory.get_latex_manager()

        # dummy==True deactivate all methods
        if dummy:
            nop = lambda *args, **kwargs: None
            for m in RendererPgf.__dict__.keys():
                if m.startswith("draw_"):
                    self.__dict__[m] = nop 
Example #6
Source File: backend_pgf.py    From ImageFusion with MIT License 6 votes vote down vote up
def get_fontspec():
    """Build fontspec preamble from rc."""
    latex_fontspec = []
    texcommand = get_texcommand()

    if texcommand != "pdflatex":
        latex_fontspec.append("\\usepackage{fontspec}")

    if texcommand != "pdflatex" and rcParams.get("pgf.rcfonts", True):
        # try to find fonts from rc parameters
        families = ["serif", "sans-serif", "monospace"]
        fontspecs = [r"\setmainfont{%s}", r"\setsansfont{%s}",
                     r"\setmonofont{%s}"]
        for family, fontspec in zip(families, fontspecs):
            matches = [f for f in rcParams["font." + family]
                       if f in system_fonts]
            if matches:
                latex_fontspec.append(fontspec % matches[0])
            else:
                pass  # no fonts found, fallback to LaTeX defaule

    return "\n".join(latex_fontspec) 
Example #7
Source File: backend_gtk.py    From neural-network-animation with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(six.text_type(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #8
Source File: backend_pgf.py    From neural-network-animation with MIT License 6 votes vote down vote up
def get_fontspec():
    """Build fontspec preamble from rc."""
    latex_fontspec = []
    texcommand = get_texcommand()

    if texcommand != "pdflatex":
        latex_fontspec.append("\\usepackage{fontspec}")

    if texcommand != "pdflatex" and rcParams.get("pgf.rcfonts", True):
        # try to find fonts from rc parameters
        families = ["serif", "sans-serif", "monospace"]
        fontspecs = [r"\setmainfont{%s}", r"\setsansfont{%s}",
                     r"\setmonofont{%s}"]
        for family, fontspec in zip(families, fontspecs):
            matches = [f for f in rcParams["font." + family]
                       if f in system_fonts]
            if matches:
                latex_fontspec.append(fontspec % matches[0])
            else:
                pass  # no fonts found, fallback to LaTeX defaule

    return "\n".join(latex_fontspec) 
Example #9
Source File: backend_gtk3.py    From neural-network-animation with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(six.text_type(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #10
Source File: backend_gtk3.py    From Computable with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(unicode(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #11
Source File: backend_pgf.py    From ImageFusion with MIT License 6 votes vote down vote up
def print_pgf(self, fname_or_fh, *args, **kwargs):
        """
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pgf is to be written to
        if is_string_like(fname_or_fh):
            with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
                self._print_pgf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            if not os.path.exists(fname_or_fh.name):
                warnings.warn("streamed pgf-code does not support raster "
                              "graphics, consider using the pgf-to-pdf option",
                              UserWarning)
            self._print_pgf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path") 
Example #12
Source File: backend_pgf.py    From ImageFusion with MIT License 6 votes vote down vote up
def print_pdf(self, fname_or_fh, *args, **kwargs):
        """
        Use LaTeX to compile a Pgf generated figure to PDF.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pdf is to be written to
        if is_string_like(fname_or_fh):
            with open(fname_or_fh, "wb") as fh:
                self._print_pdf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            self._print_pdf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path or a file-like object") 
Example #13
Source File: backend_gtk.py    From Computable with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(unicode(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #14
Source File: backend_gtk.py    From Computable with MIT License 6 votes vote down vote up
def button_press_event(self, widget, event):
        if _debug: print('FigureCanvasGTK.%s' % fn_name())
        x = event.x
        # flipy so y=0 is bottom of canvas
        y = self.allocation.height - event.y
        dblclick = (event.type == gdk._2BUTTON_PRESS)
        if not dblclick:
            # GTK is the only backend that generates a DOWN-UP-DOWN-DBLCLICK-UP  event
            # sequence for a double click.  All other backends have a DOWN-UP-DBLCLICK-UP
            # sequence.  In order to provide consistency to matplotlib users, we will
            # eat the extra DOWN event in the case that we detect it is part of a double
            # click.
            # first, get the double click time in milliseconds.
            current_time  = event.get_time()
            last_time     = self.last_downclick.get(event.button,0)
            dblclick_time = gtk.settings_get_for_screen(gdk.screen_get_default()).get_property('gtk-double-click-time')
            delta_time    = current_time-last_time
            if delta_time < dblclick_time:
                del self.last_downclick[event.button] # we do not want to eat more than one event.
                return False                          # eat.
            self.last_downclick[event.button] = current_time
        FigureCanvasBase.button_press_event(self, x, y, event.button, dblclick=dblclick, guiEvent=event)
        return False  # finish event propagation? 
Example #15
Source File: backend_pgf.py    From ImageFusion with MIT License 6 votes vote down vote up
def get_latex_manager():
        texcommand = get_texcommand()
        latex_header = LatexManager._build_latex_header()
        prev = LatexManagerFactory.previous_instance

        # check if the previous instance of LatexManager can be reused
        if prev and prev.latex_header == latex_header and prev.texcommand == texcommand:
            if rcParams.get("pgf.debug", False):
                print("reusing LatexManager")
            return prev
        else:
            if rcParams.get("pgf.debug", False):
                print("creating LatexManager")
            new_inst = LatexManager()
            LatexManagerFactory.previous_instance = new_inst
            return new_inst 
Example #16
Source File: backend_pgf.py    From Computable with MIT License 6 votes vote down vote up
def print_pdf(self, fname_or_fh, *args, **kwargs):
        """
        Use LaTeX to compile a Pgf generated figure to PDF.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pdf is to be written to
        if is_string_like(fname_or_fh):
            with open(fname_or_fh, "wb") as fh:
                self._print_pdf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            self._print_pdf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path or a file-like object") 
Example #17
Source File: backend_gtk.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def button_press_event(self, widget, event):
        if _debug: print('FigureCanvasGTK.%s' % fn_name())
        x = event.x
        # flipy so y=0 is bottom of canvas
        y = self.allocation.height - event.y
        dblclick = (event.type == gdk._2BUTTON_PRESS)
        if not dblclick:
            # GTK is the only backend that generates a DOWN-UP-DOWN-DBLCLICK-UP  event
            # sequence for a double click.  All other backends have a DOWN-UP-DBLCLICK-UP
            # sequence.  In order to provide consistency to matplotlib users, we will
            # eat the extra DOWN event in the case that we detect it is part of a double
            # click.
            # first, get the double click time in milliseconds.
            current_time  = event.get_time()
            last_time     = self.last_downclick.get(event.button,0)
            dblclick_time = gtk.settings_get_for_screen(gdk.screen_get_default()).get_property('gtk-double-click-time')
            delta_time    = current_time-last_time
            if delta_time < dblclick_time:
                del self.last_downclick[event.button] # we do not want to eat more than one event.
                return False                          # eat.
            self.last_downclick[event.button] = current_time
        FigureCanvasBase.button_press_event(self, x, y, event.button, dblclick=dblclick, guiEvent=event)
        return False  # finish event propagation? 
Example #18
Source File: backend_gtk3.py    From ImageFusion with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(six.text_type(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #19
Source File: backend_gtk.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(unicode(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #20
Source File: backend_gtk.py    From neural-network-animation with MIT License 6 votes vote down vote up
def button_press_event(self, widget, event):
        if _debug: print('FigureCanvasGTK.%s' % fn_name())
        x = event.x
        # flipy so y=0 is bottom of canvas
        y = self.allocation.height - event.y
        dblclick = (event.type == gdk._2BUTTON_PRESS)
        if not dblclick:
            # GTK is the only backend that generates a DOWN-UP-DOWN-DBLCLICK-UP  event
            # sequence for a double click.  All other backends have a DOWN-UP-DBLCLICK-UP
            # sequence.  In order to provide consistency to matplotlib users, we will
            # eat the extra DOWN event in the case that we detect it is part of a double
            # click.
            # first, get the double click time in milliseconds.
            current_time  = event.get_time()
            last_time     = self.last_downclick.get(event.button,0)
            dblclick_time = gtk.settings_get_for_screen(gdk.screen_get_default()).get_property('gtk-double-click-time')
            delta_time    = current_time-last_time
            if delta_time < dblclick_time:
                del self.last_downclick[event.button] # we do not want to eat more than one event.
                return False                          # eat.
            self.last_downclick[event.button] = current_time
        FigureCanvasBase.button_press_event(self, x, y, event.button, dblclick=dblclick, guiEvent=event)
        return False  # finish event propagation? 
Example #21
Source File: backend_pgf.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def print_pdf(self, fname_or_fh, *args, **kwargs):
        """
        Use LaTeX to compile a Pgf generated figure to PDF.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pdf is to be written to
        if is_string_like(fname_or_fh):
            with open(fname_or_fh, "wb") as fh:
                self._print_pdf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            self._print_pdf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path or a file-like object") 
Example #22
Source File: backend_gtk3.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(unicode(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #23
Source File: backend_gtk.py    From ImageFusion with MIT License 6 votes vote down vote up
def save_figure(self, *args):
        chooser = self.get_filechooser()
        fname, format = chooser.get_filename_from_user()
        chooser.destroy()
        if fname:
            startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
            if startpath == '':
                # explicitly missing key or empty str signals to use cwd
                rcParams['savefig.directory'] = startpath
            else:
                # save dir for next time
                rcParams['savefig.directory'] = os.path.dirname(six.text_type(fname))
            try:
                self.canvas.print_figure(fname, format=format)
            except Exception as e:
                error_msg_gtk(str(e), parent=self) 
Example #24
Source File: backend_pgf.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def print_pgf(self, fname_or_fh, *args, **kwargs):
        """
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pgf is to be written to
        if is_string_like(fname_or_fh):
            with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
                self._print_pgf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            raise ValueError("saving pgf to a stream is not supported, " +
                             "consider using the pdf option of the pgf-backend")
        else:
            raise ValueError("filename must be a path") 
Example #25
Source File: backend_gtk.py    From ImageFusion with MIT License 6 votes vote down vote up
def button_press_event(self, widget, event):
        if _debug: print('FigureCanvasGTK.%s' % fn_name())
        x = event.x
        # flipy so y=0 is bottom of canvas
        y = self.allocation.height - event.y
        dblclick = (event.type == gdk._2BUTTON_PRESS)
        if not dblclick:
            # GTK is the only backend that generates a DOWN-UP-DOWN-DBLCLICK-UP  event
            # sequence for a double click.  All other backends have a DOWN-UP-DBLCLICK-UP
            # sequence.  In order to provide consistency to matplotlib users, we will
            # eat the extra DOWN event in the case that we detect it is part of a double
            # click.
            # first, get the double click time in milliseconds.
            current_time  = event.get_time()
            last_time     = self.last_downclick.get(event.button,0)
            dblclick_time = gtk.settings_get_for_screen(gdk.screen_get_default()).get_property('gtk-double-click-time')
            delta_time    = current_time-last_time
            if delta_time < dblclick_time:
                del self.last_downclick[event.button] # we do not want to eat more than one event.
                return False                          # eat.
            self.last_downclick[event.button] = current_time
        FigureCanvasBase.button_press_event(self, x, y, event.button, dblclick=dblclick, guiEvent=event)
        return False  # finish event propagation? 
Example #26
Source File: backend_pgf.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def get_fontspec():
    """Build fontspec preamble from rc."""
    latex_fontspec = []
    texcommand = get_texcommand()

    if texcommand != "pdflatex":
        latex_fontspec.append(r"\usepackage{fontspec}")

    if texcommand != "pdflatex" and rcParams.get("pgf.rcfonts", True):
        # try to find fonts from rc parameters
        families = ["serif", "sans-serif", "monospace"]
        fontspecs = [r"\setmainfont{%s}", r"\setsansfont{%s}",
                     r"\setmonofont{%s}"]
        for family, fontspec in zip(families, fontspecs):
            matches = [f for f in rcParams["font." + family]
                       if f in system_fonts]
            if matches:
                latex_fontspec.append(fontspec % matches[0])
            else:
                pass  # no fonts found, fallback to LaTeX defaule

    return "\n".join(latex_fontspec) 
Example #27
Source File: backend_pgf.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def get_latex_manager():
        texcommand = get_texcommand()
        latex_header = LatexManager._build_latex_header()
        prev = LatexManagerFactory.previous_instance

        # check if the previous instance of LatexManager can be reused
        if prev and prev.latex_header == latex_header and prev.texcommand == texcommand:
            if rcParams.get("pgf.debug", False):
                print("reusing LatexManager")
            return prev
        else:
            if rcParams.get("pgf.debug", False):
                print("creating LatexManager")
            new_inst = LatexManager()
            LatexManagerFactory.previous_instance = new_inst
            return new_inst 
Example #28
Source File: backend_pgf.py    From neural-network-animation with MIT License 6 votes vote down vote up
def print_pdf(self, fname_or_fh, *args, **kwargs):
        """
        Use LaTeX to compile a Pgf generated figure to PDF.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pdf is to be written to
        if is_string_like(fname_or_fh):
            with open(fname_or_fh, "wb") as fh:
                self._print_pdf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            self._print_pdf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path or a file-like object") 
Example #29
Source File: backend_pgf.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def __init__(self, figure, fh, dummy=False):
        """
        Creates a new PGF renderer that translates any drawing instruction
        into text commands to be interpreted in a latex pgfpicture environment.

        Attributes:
        * figure: Matplotlib figure to initialize height, width and dpi from.
        * fh: File handle for the output of the drawing commands.
        """
        RendererBase.__init__(self)
        self.dpi = figure.dpi
        self.fh = fh
        self.figure = figure
        self.image_counter = 0

        # get LatexManager instance
        self.latexManager = LatexManagerFactory.get_latex_manager()

        # dummy==True deactivate all methods
        if dummy:
            nop = lambda *args, **kwargs: None
            for m in RendererPgf.__dict__.keys():
                if m.startswith("draw_"):
                    self.__dict__[m] = nop 
Example #30
Source File: backend_pgf.py    From neural-network-animation with MIT License 6 votes vote down vote up
def print_pgf(self, fname_or_fh, *args, **kwargs):
        """
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pgf is to be written to
        if is_string_like(fname_or_fh):
            with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
                self._print_pgf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            if not os.path.exists(fname_or_fh.name):
                warnings.warn("streamed pgf-code does not support raster "
                              "graphics, consider using the pgf-to-pdf option",
                              UserWarning)
            self._print_pgf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path")