Graphics Output Types - The Sage Command Line

Skip to content
Back to top
View this page
Edit this page

# Graphics Output Types

This module defines the rich output types for 2-d images, both vector and raster graphics.

class sage.repl.rich_output.output_graphics.OutputImageDvi(dvi)

  Bases: `OutputBase`

  DVI Image.

  INPUT:

  - `dvi` – `OutputBuffer`. Alternatively, a string (bytes) can be passed directly which will then be converted into an `OutputBuffer`. The DVI data.

  EXAMPLES:

  Sage

      sage: from sage.repl.rich_output.output_catalog import OutputImageDvi
      sage: OutputImageDvi.example()     # indirect doctest
      OutputImageDvi container

  Python

      >>> from sage.all import *
      >>> from sage.repl.rich_output.output_catalog import OutputImageDvi
      >>> OutputImageDvi.example()     # indirect doctest
      OutputImageDvi container

  classmethod example()

    Construct a sample DVI output container.

    This static method is meant for doctests, so they can easily construct an example.

    OUTPUT: an instance of `OutputImageDvi`

    EXAMPLES:

    Sage

        sage: from sage.repl.rich_output.output_catalog import OutputImageDvi
        sage: OutputImageDvi.example()
        OutputImageDvi container
        sage: OutputImageDvi.example().dvi
        buffer containing 212 bytes
        sage: b'TeX output' in OutputImageDvi.example().dvi.get()
        True

    Python

        >>> from sage.all import *
        >>> from sage.repl.rich_output.output_catalog import OutputImageDvi
        >>> OutputImageDvi.example()
        OutputImageDvi container
        >>> OutputImageDvi.example().dvi
        buffer containing 212 bytes
        >>> b'TeX output' in OutputImageDvi.example().dvi.get()
        True

class sage.repl.rich_output.output_graphics.OutputImageGif(gif)

  Bases: `OutputBase`

  GIF Image (possibly animated).

  INPUT:

  - `gif` – `OutputBuffer`. Alternatively, a string (bytes) can be passed directly which will then be converted into an `OutputBuffer`. The GIF image data.

  EXAMPLES:

  Sage

      sage: from sage.repl.rich_output.output_catalog import OutputImageGif
      sage: OutputImageGif.example()   # indirect doctest
      OutputImageGif container

  Python

      >>> from sage.all import *
      >>> from sage.repl.rich_output.output_catalog import OutputImageGif
      >>> OutputImageGif.example()   # indirect doctest
      OutputImageGif container

  classmethod example()

    Construct a sample GIF output container.

    This static method is meant for doctests, so they can easily construct an example.

    OUTPUT: an instance of `OutputImageGif`

    EXAMPLES:

    Sage

        sage: from sage.repl.rich_output.output_catalog import OutputImageGif
        sage: OutputImageGif.example()
        OutputImageGif container
        sage: OutputImageGif.example().gif
        buffer containing 408 bytes
        sage: OutputImageGif.example().gif.get().startswith(b'GIF89a')
        True

    Python

        >>> from sage.all import *
        >>> from sage.repl.rich_output.output_catalog import OutputImageGif
        >>> OutputImageGif.example()
        OutputImageGif container
        >>> OutputImageGif.example().gif
        buffer containing 408 bytes
        >>> OutputImageGif.example().gif.get().startswith(b'GIF89a')
        True

  html_fragment()

    Return a self-contained HTML fragment displaying the image.

    This is a workaround for the Jupyter notebook which doesn’t support GIF directly.

    OUTPUT: string. HTML fragment for displaying the GIF image

    EXAMPLES:

    Sage

        sage: from sage.repl.rich_output.output_catalog import OutputImageGif
        sage: OutputImageGif.example().html_fragment()
        '<img src="data:image/gif;base64,R0lGODl...zd3t/g4eLj5OVDQQA7"/>'

    Python

        >>> from sage.all import *
        >>> from sage.repl.rich_output.output_catalog import OutputImageGif
        >>> OutputImageGif.example().html_fragment()
        '<img src="data:image/gif;base64,R0lGODl...zd3t/g4eLj5OVDQQA7"/>'

class sage.repl.rich_output.output_graphics.OutputImageJpg(jpg)

  Bases: `OutputBase`

  JPEG Image.

  INPUT:

  - `jpg` – `OutputBuffer`. Alternatively, a string (bytes) can be passed directly which will then be converted into an `OutputBuffer`. The JPEG image data.

  EXAMPLES:

  Sage

      sage: from sage.repl.rich_output.output_catalog import OutputImageJpg
      sage: OutputImageJpg.example()   # indirect doctest
      OutputImageJpg container

  Python

      >>> from sage.all import *
      >>> from sage.repl.rich_output.output_catalog import OutputImageJpg
      >>> OutputImageJpg.example()   # indirect doctest
      OutputImageJpg container

  classmethod example()

    Construct a sample JPEG output container.

    This static method is meant for doctests, so they can easily construct an example.

    OUTPUT: an instance of `OutputImageJpg`

    EXAMPLES:

    Sage

        sage: from sage.repl.rich_output.output_catalog import OutputImageJpg
        sage: OutputImageJpg.example()
        OutputImageJpg container
        sage: OutputImageJpg.example().jpg
        buffer containing 978 bytes
        sage: OutputImageJpg.example().jpg.get().startswith(b'\xff\xd8\xff\xe0\x00\x10JFIF')
        True

    Python

        >>> from sage.all import *
        >>> from sage.repl.rich_output.output_catalog import OutputImageJpg
        >>> OutputImageJpg.example()
        OutputImageJpg container
        >>> OutputImageJpg.example().jpg
        buffer containing 978 bytes
        >>> OutputImageJpg.example().jpg.get().startswith(b'\xff\xd8\xff\xe0\x00\x10JFIF')
        True

class sage.repl.rich_output.output_graphics.OutputImagePdf(pdf)

  Bases: `OutputBase`

  PDF Image.

  INPUT:

  - `pdf` – `OutputBuffer`. Alternatively, a string (bytes) can be passed directly which will then be converted into an `OutputBuffer`. The PDF data.

  EXAMPLES:

  Sage

      sage: from sage.repl.rich_output.output_catalog import OutputImagePdf
      sage: OutputImagePdf.example()   # indirect doctest
      OutputImagePdf container

  Python

      >>> from sage.all import *
      >>> from sage.repl.rich_output.output_catalog import OutputImagePdf
      >>> OutputImagePdf.example()   # indirect doctest
      OutputImagePdf container

  classmethod example()

    Construct a sample PDF output container.

    This static method is meant for doctests, so they can easily construct an example.

    OUTPUT: an instance of `OutputImagePdf`

    EXAMPLES:

    Sage

        sage: from sage.repl.rich_output.output_catalog import OutputImagePdf
        sage: OutputImagePdf.example()
        OutputImagePdf container
        sage: OutputImagePdf.example().pdf
        buffer containing 4285 bytes
        sage: OutputImagePdf.example().pdf.get().startswith(b'%PDF-1.4')
        True

    Python

        >>> from sage.all import *
        >>> from sage.repl.rich_output.output_catalog import OutputImagePdf
        >>> OutputImagePdf.example()
        OutputImagePdf container
        >>> OutputImagePdf.example().pdf
        buffer containing 4285 bytes
        >>> OutputImagePdf.example().pdf.get().startswith(b'%PDF-1.4')
        True

class sage.repl.rich_output.output_graphics.OutputImagePng(png)

  Bases: `OutputBase`

  PNG Image.

  Note

  Every backend that is capable of displaying any kind of graphics is supposed to support the PNG format at least.

  INPUT:

  - `png` – `OutputBuffer`. Alternatively, a string (bytes) can be passed directly which will then be converted into an `OutputBuffer`. The PNG image data.

  EXAMPLES:

  Sage

      sage: from sage.repl.rich_output.output_catalog import OutputImagePng
      sage: OutputImagePng.example()  # indirect doctest
      OutputImagePng container

  Python

      >>> from sage.all import *
      >>> from sage.repl.rich_output.output_catalog import OutputImagePng
      >>> OutputImagePng.example()  # indirect doctest
      OutputImagePng container

  classmethod example()

    Construct a sample PNG output container.

    This static method is meant for doctests, so they can easily construct an example.

    OUTPUT: an instance of `OutputImagePng`

    EXAMPLES:

    Sage

        sage: from sage.repl.rich_output.output_catalog import OutputImagePng
        sage: OutputImagePng.example()
        OutputImagePng container
        sage: OutputImagePng.example().png
        buffer containing 608 bytes
        sage: OutputImagePng.example().png.get().startswith(b'\x89PNG')
        True

    Python

        >>> from sage.all import *
        >>> from sage.repl.rich_output.output_catalog import OutputImagePng
        >>> OutputImagePng.example()
        OutputImagePng container
        >>> OutputImagePng.example().png
        buffer containing 608 bytes
        >>> OutputImagePng.example().png.get().startswith(b'\x89PNG')
        True

class sage.repl.rich_output.output_graphics.OutputImageSvg(svg)

  Bases: `OutputBase`

  SVG Image.

  INPUT:

  - `svg` – `OutputBuffer`. Alternatively, a string (bytes) can be passed directly which will then be converted into an `OutputBuffer`. The SVG image data.

  EXAMPLES:

  Sage

      sage: from sage.repl.rich_output.output_catalog import OutputImageSvg
      sage: OutputImageSvg.example()   # indirect doctest
      OutputImageSvg container

  Python

      >>> from sage.all import *
      >>> from sage.repl.rich_output.output_catalog import OutputImageSvg
      >>> OutputImageSvg.example()   # indirect doctest
      OutputImageSvg container

  classmethod example()

    Construct a sample SVG output container.

    This static method is meant for doctests, so they can easily construct an example.

    OUTPUT: an instance of `OutputImageSvg`

    EXAMPLES:

    Sage

        sage: from sage.repl.rich_output.output_catalog import OutputImageSvg
        sage: OutputImageSvg.example()
        OutputImageSvg container
        sage: OutputImageSvg.example().svg
        buffer containing 1422 bytes
        sage: b'</svg>' in OutputImageSvg.example().svg.get()
        True

    Python

        >>> from sage.all import *
        >>> from sage.repl.rich_output.output_catalog import OutputImageSvg
        >>> OutputImageSvg.example()
        OutputImageSvg container
        >>> OutputImageSvg.example().svg
        buffer containing 1422 bytes
        >>> b'</svg>' in OutputImageSvg.example().svg.get()
        True