<commit_before>"""Plotting module for Sympy.

A plot is represented by the ``Plot`` class that contains a reference to the
backend and a list of the data series to be plotted. The data series are
instances of classes meant to simplify getting points and meshes from sympy
expressions. ``plot_backends`` is a dictionary with all the backends.

This module gives only the essential. For all the fancy stuff use directly
the backend. You can get the backend wrapper for every plot from the
``_backend`` attribute. Moreover the data series classes have various useful
methods like ``get_points``, ``get_segments``, ``get_meshes``, etc, that may
be useful if you wish to use another plotting library.

Especially if you need publication ready graphs and this module is not enough
for you - just get the ``_backend`` attribute and add whatever you want
directly to it. In the case of matplotlib (the common way to graph data in
python) just copy ``_backend.fig`` which is the figure and ``_backend.ax``
which is the axis and work on them as you would on any other matplotlib object.

Simplicity of code takes much greater importance than performance. Don't use it
if you care at all about performance. A new backend instance is initialized
every time you call ``show()`` and the old one is left to the garbage collector.
"""

from inspect import getargspec
from itertools import repeat, izip
from sympy import sympify, Expr, Tuple, Dummy
from sympy.external import import_module
from sympy.core.compatibility import set_union
import warnings
from experimental_lambdify import (vectorized_lambdify, lambdify)

#TODO probably all of the imports after this line can be put inside function to
# speed up the `from sympy import *` command.
np = import_module('numpy')

# Backend specific imports - matplotlib
matplotlib = import_module('matplotlib',
    __import__kwargs={'fromlist':['pyplot', 'cm', 'collections']},
    min_module_version='1.0.0')
if matplotlib:
    plt = matplotlib.pyplot
    cm = matplotlib.cm
    LineCollection = matplotlib.collections.LineCollection
    mpl_toolkits = import_module('mpl_toolkits',
            __import__kwargs={'fromlist':['mplot3d']})
    Axes3D = mpl_toolkits.mplot3d.Axes3D
    art3d = mpl_toolkits.mplot3d.art3d
    ListedColormap = matplotlib.colors.ListedColormap

# Backend specific imports - textplot
from sympy.plotting.textplot import textplot


##############################################################################
# The public interface
##############################################################################

class Plot(object):
    """The central class of the plotting module.

    For interactive work the function ``plot`` is better suited.

    This class permits the plotting of sympy expressions using numerous
    backends (matplotlib, textplot, the old pyglet module for sympy, Google
    charts api, etc).<commit_msg>Catch RuntimeError when importing matplotlib<commit_after>"""Plotting module for Sympy.

A plot is represented by the ``Plot`` class that contains a reference to the
backend and a list of the data series to be plotted. The data series are
instances of classes meant to simplify getting points and meshes from sympy
expressions. ``plot_backends`` is a dictionary with all the backends.

This module gives only the essential. For all the fancy stuff use directly
the backend. You can get the backend wrapper for every plot from the
``_backend`` attribute. Moreover the data series classes have various useful
methods like ``get_points``, ``get_segments``, ``get_meshes``, etc, that may
be useful if you wish to use another plotting library.

Especially if you need publication ready graphs and this module is not enough
for you - just get the ``_backend`` attribute and add whatever you want
directly to it. In the case of matplotlib (the common way to graph data in
python) just copy ``_backend.fig`` which is the figure and ``_backend.ax``
which is the axis and work on them as you would on any other matplotlib object.

Simplicity of code takes much greater importance than performance. Don't use it
if you care at all about performance. A new backend instance is initialized
every time you call ``show()`` and the old one is left to the garbage collector.
"""

from inspect import getargspec
from itertools import repeat, izip
from sympy import sympify, Expr, Tuple, Dummy
from sympy.external import import_module
from sympy.core.compatibility import set_union
import warnings
from experimental_lambdify import (vectorized_lambdify, lambdify)

#TODO probably all of the imports after this line can be put inside function to
# speed up the `from sympy import *` command.
np = import_module('numpy')

# Backend specific imports - matplotlib
matplotlib = import_module('matplotlib',
    __import__kwargs={'fromlist':['pyplot', 'cm', 'collections']},
    min_module_version='1.0.0', catch=(RuntimeError,))
if matplotlib:
    plt = matplotlib.pyplot
    cm = matplotlib.cm
    LineCollection = matplotlib.collections.LineCollection
    mpl_toolkits = import_module('mpl_toolkits',
            __import__kwargs={'fromlist':['mplot3d']})
    Axes3D = mpl_toolkits.mplot3d.Axes3D
    art3d = mpl_toolkits.mplot3d.art3d
    ListedColormap = matplotlib.colors.ListedColormap

# Backend specific imports - textplot
from sympy.plotting.textplot import textplot


##############################################################################
# The public interface
##############################################################################

class Plot(object):
    """The central class of the plotting module.

    For interactive work the function ``plot`` is better suited.

    This class permits the plotting of sympy expressions using numerous
    backends (matplotlib, textplot, the old pyglet module for sympy, Google
    charts api, etc).
{'fraction_non_alphanumeric': 0.11688980432543769, 'fraction_numerical': 0.0034328870580157913, 'mean_word_length': 4.9459183673469385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6923123', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1532, 'n_words': 700}