<commit_before>from __future__ import print_function
import numpy as np
import warnings
from ..utils import mkvc, ndgrid, requires
from ..utils.code_utils import deprecate_method
from six import integer_types

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import matplotlib.colors as colors
import matplotlib.cm as cmx
from matplotlib.collections import PolyCollection, LineCollection
from matplotlib import rc_params
from mpl_toolkits.mplot3d.art3d import Line3DCollection
import matplotlib.transforms as mtransforms
import discretize

class InterfaceMPL(object):
    """This class is used for simple ``discretize`` mesh plotting using matplotlib.

    This interface adds three methods to the meshes. ``plot_grid`` will plot the
    grid points of each mesh in 2D and 3D. ``plot_image`` for 2D image ploting of
    models. and ``plot_slice`` for plotting a 2D slice through a 3D mesh.
    """

    def plot_grid(
        self, ax=None, nodes=False, faces=False, centers=False, edges=False,
        lines=True, show_it=False, **kwargs
    ):
        """Plot the nodal, cell-centered and staggered grids.

        Parameters
        ----------
        ax : matplotlib.axes.Axes or None, optional
            The axes to draw on. None produces a new Axes.
        nodes, faces, centers, edges, lines : bool, optional
            Whether to plot the corresponding item
        show_it : bool, optional
            whether to call plt.show()
        color : Color or str, optional
            If lines=True, the color of the lines, defaults to first color.
        linewidth : float, optional
            If lines=True, the linewidth for the lines.
        edges_x, edges_y, edges_z, faces_x, faces_y, faces_z : bool, optional
            When plotting a ``TreeMesh``, these are also options to plot the
            individual component items.
        cell_line : bool, optional
            When plotting a ``TreeMesh``, you can also plot a line through the
            cell centers in order.
        slice : {'both', 'theta', 'z'}
            When plotting a ``CylindricalMesh``, which dimension to slice over.

        Returns
        -------
        matplotlib.axes.Axes
            Axes handle for the plot

        Examples
        --------

        Plotting a 2D TensorMesh grid
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> import numpy as np
        >>> h1 = np.linspace(.1, .5, 3)
        >>> h2 = np.linspace(.1, .5, 5)
        >>> mesh = discretize.TensorMesh([h1, h2])
        >>> mesh.plot_grid(nodes=True, faces=True, centers=True, lines=True)
        >>> plt.show()

        Plotting a 3D TensorMesh grid
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> import numpy as np
        >>> h1 = np.linspace(.1, .5, 3)
        >>> h2 = np.linspace(.1, .5, 5)
        >>> h3 = np.linspace(.1, .5, 3)
        >>> mesh = discretize.TensorMesh([h1, h2, h3])
        >>> mesh.plot_grid(nodes=True, faces=True, centers=True, lines=True)
        >>> plt.show()

        Plotting a 2D CurvilinearMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> X, Y = discretize.utils.exampleLrmGrid([10, 10], 'rotate')
        >>> M = discretize.CurvilinearMesh([X, Y])
        >>> M.plot_grid()
        >>> plt.show()

        Plotting a 3D CurvilinearMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> X, Y, Z = discretize.utils.exampleLrmGrid([5, 5, 5], 'rotate')
        >>> M = discretize.CurvilinearMesh([X, Y, Z])
        >>> M.plot_grid()
        >>> plt.show()

        Plotting a 2D TreeMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> M = discretize.TreeMesh([32, 32])
        >>> M.insert_cells([[0.25, 0.25]], [4])
        >>> M.plot_grid()
        >>> plt.show()

        Plotting a 3D TreeMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> M = discretize.TreeMesh([32, 32, 32])
        >>> M.insert_cells([[0.3, 0.75, 0.22]], [4])
        >>> M.plot_grid()
        >>> plt.show()

        """
        mesh_type = self._meshType.lower()
        plotters = {
            'tree' : self.__plot_grid_tree,
            'tensor': self.__plot_grid_tensor,
            'curv': self.__plot_grid_curv,
            'cyl': self.__plot_grid_cyl,
        }
        try:
            plotter = plotters[mesh_type]
        except KeyError:
            raise NotImplementedError('Mesh type `{}` does not have a plot_grid implementation.'.format(type(self).__name__))


        if "showIt" in kwargs:
            show_it = kwargs.pop("showIt")
            warnings.warn("showIt has been deprecated, please use show_it", FutureWarning)

        axOpts = {'projection': '3d'} if self.dim == 3 else {}
        if ax is None and mesh_type != 'cyl':
            plt.figure()
            ax = plt.subplot(111, **axOpts)
        else:
            if not isinstance(ax, (list, tuple, np.ndarray)):
                ax_test = (ax, )
            else:
                ax_test = ax
            for a in ax_test:
                if not isinstance(a, matplotlib.axes.Axes):
                    raise TypeError("ax must be an matplotlib.axes.Axes")

        rcParams = rc_params()
        if lines:
            kwargs['color'] = kwargs.get('color', rcParams['lines.color'])<commit_msg>set ax_test when already a list<commit_after>from __future__ import print_function
import numpy as np
import warnings
from ..utils import mkvc, ndgrid, requires
from ..utils.code_utils import deprecate_method
from six import integer_types

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import matplotlib.colors as colors
import matplotlib.cm as cmx
from matplotlib.collections import PolyCollection, LineCollection
from matplotlib import rc_params
from mpl_toolkits.mplot3d.art3d import Line3DCollection
import matplotlib.transforms as mtransforms
import discretize

class InterfaceMPL(object):
    """This class is used for simple ``discretize`` mesh plotting using matplotlib.

    This interface adds three methods to the meshes. ``plot_grid`` will plot the
    grid points of each mesh in 2D and 3D. ``plot_image`` for 2D image ploting of
    models. and ``plot_slice`` for plotting a 2D slice through a 3D mesh.
    """

    def plot_grid(
        self, ax=None, nodes=False, faces=False, centers=False, edges=False,
        lines=True, show_it=False, **kwargs
    ):
        """Plot the nodal, cell-centered and staggered grids.

        Parameters
        ----------
        ax : matplotlib.axes.Axes or None, optional
            The axes to draw on. None produces a new Axes.
        nodes, faces, centers, edges, lines : bool, optional
            Whether to plot the corresponding item
        show_it : bool, optional
            whether to call plt.show()
        color : Color or str, optional
            If lines=True, the color of the lines, defaults to first color.
        linewidth : float, optional
            If lines=True, the linewidth for the lines.
        edges_x, edges_y, edges_z, faces_x, faces_y, faces_z : bool, optional
            When plotting a ``TreeMesh``, these are also options to plot the
            individual component items.
        cell_line : bool, optional
            When plotting a ``TreeMesh``, you can also plot a line through the
            cell centers in order.
        slice : {'both', 'theta', 'z'}
            When plotting a ``CylindricalMesh``, which dimension to slice over.

        Returns
        -------
        matplotlib.axes.Axes
            Axes handle for the plot

        Examples
        --------

        Plotting a 2D TensorMesh grid
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> import numpy as np
        >>> h1 = np.linspace(.1, .5, 3)
        >>> h2 = np.linspace(.1, .5, 5)
        >>> mesh = discretize.TensorMesh([h1, h2])
        >>> mesh.plot_grid(nodes=True, faces=True, centers=True, lines=True)
        >>> plt.show()

        Plotting a 3D TensorMesh grid
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> import numpy as np
        >>> h1 = np.linspace(.1, .5, 3)
        >>> h2 = np.linspace(.1, .5, 5)
        >>> h3 = np.linspace(.1, .5, 3)
        >>> mesh = discretize.TensorMesh([h1, h2, h3])
        >>> mesh.plot_grid(nodes=True, faces=True, centers=True, lines=True)
        >>> plt.show()

        Plotting a 2D CurvilinearMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> X, Y = discretize.utils.exampleLrmGrid([10, 10], 'rotate')
        >>> M = discretize.CurvilinearMesh([X, Y])
        >>> M.plot_grid()
        >>> plt.show()

        Plotting a 3D CurvilinearMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> X, Y, Z = discretize.utils.exampleLrmGrid([5, 5, 5], 'rotate')
        >>> M = discretize.CurvilinearMesh([X, Y, Z])
        >>> M.plot_grid()
        >>> plt.show()

        Plotting a 2D TreeMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> M = discretize.TreeMesh([32, 32])
        >>> M.insert_cells([[0.25, 0.25]], [4])
        >>> M.plot_grid()
        >>> plt.show()

        Plotting a 3D TreeMesh
        >>> from matplotlib import pyplot as plt
        >>> import discretize
        >>> M = discretize.TreeMesh([32, 32, 32])
        >>> M.insert_cells([[0.3, 0.75, 0.22]], [4])
        >>> M.plot_grid()
        >>> plt.show()

        """
        mesh_type = self._meshType.lower()
        plotters = {
            'tree' : self.__plot_grid_tree,
            'tensor': self.__plot_grid_tensor,
            'curv': self.__plot_grid_curv,
            'cyl': self.__plot_grid_cyl,
        }
        try:
            plotter = plotters[mesh_type]
        except KeyError:
            raise NotImplementedError('Mesh type `{}` does not have a plot_grid implementation.'.format(type(self).__name__))


        if "showIt" in kwargs:
            show_it = kwargs.pop("showIt")
            warnings.warn("showIt has been deprecated, please use show_it", FutureWarning)

        axOpts = {'projection': '3d'} if self.dim == 3 else {}
        if ax is None and mesh_type != 'cyl':
            plt.figure()
            ax = plt.subplot(111, **axOpts)
        else:
            ax_test = ax
            if not isinstance(ax, (list, tuple, np.ndarray)):
                ax_test = (ax, )
            for a in ax_test:
                if not isinstance(a, matplotlib.axes.Axes):
                    raise TypeError("ax must be an matplotlib.axes.Axes")

        rcParams = rc_params()
        if lines:
            kwargs['color'] = kwargs.get('color', rcParams['lines.color'])
{'fraction_non_alphanumeric': 0.11421505770287599, 'fraction_numerical': 0.014105147462905294, 'mean_word_length': 2.143967751223726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 249, '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': '4711159', 'n_tokens_mistral': 3315, 'n_tokens_neox': 3171, 'n_words': 1013}