<commit_before>"""
Functions to visualize the mesh connectivity with global and local DOF
numberings.
"""
import numpy as nm

import matplotlib.pyplot as plt

def _get_axes(ax, dim):
    if ax is None:
        fig = plt.figure()
        if dim == 3:
            from mpl_toolkits.mplot3d import axes3d
            axes3d # Make pyflakes happy...

            ax = fig.add_subplot(111, projection='3d')

        else:
            ax = fig.add_subplot(111)

    return ax

def _to2d(coors):
    if coors.shape[1] == 1:
        coors = nm.c_[coors, nm.zeros_like(coors)]

    return coors

def plot_points(ax, coors, vals=None, point_size=20,
                show_colorbar=False):
    """
    Plot points with given coordinates, optionally colored using `vals` values.
    """
    dim = coors.shape[1]
    ax = _get_axes(ax, dim)

    colors = 'b' if vals is None else vals

    coors = _to2d(coors)
    sc = ax.scatter(*coors.T, s=point_size, c=colors, alpha=1)

    if show_colorbar and (vals is not None):
        plt.colorbar(sc)

    return ax

def plot_mesh(ax, coors, conn, edges):
    """
    Plot a finite element mesh as a wireframe.
    """
    dim = coors.shape[1]
    ax = _get_axes(ax, dim)
    coors = _to2d(coors)

    for el in conn:
        eds = el[edges]

        for ed in eds:
            cc = coors[ed]

            ax.plot(*cc.T, color='k')

    return ax

def plot_global_dofs(ax, coors, econn):
    """
    Plot global DOF numbers given in an extended connectivity.<commit_msg>add color, **plot_kwargs arguments to plot_mesh()<commit_after>"""
Functions to visualize the mesh connectivity with global and local DOF
numberings.
"""
import numpy as nm

import matplotlib.pyplot as plt

def _get_axes(ax, dim):
    if ax is None:
        fig = plt.figure()
        if dim == 3:
            from mpl_toolkits.mplot3d import axes3d
            axes3d # Make pyflakes happy...

            ax = fig.add_subplot(111, projection='3d')

        else:
            ax = fig.add_subplot(111)

    return ax

def _to2d(coors):
    if coors.shape[1] == 1:
        coors = nm.c_[coors, nm.zeros_like(coors)]

    return coors

def plot_points(ax, coors, vals=None, point_size=20,
                show_colorbar=False):
    """
    Plot points with given coordinates, optionally colored using `vals` values.
    """
    dim = coors.shape[1]
    ax = _get_axes(ax, dim)

    colors = 'b' if vals is None else vals

    coors = _to2d(coors)
    sc = ax.scatter(*coors.T, s=point_size, c=colors, alpha=1)

    if show_colorbar and (vals is not None):
        plt.colorbar(sc)

    return ax

def plot_mesh(ax, coors, conn, edges, color='k', **plot_kwargs):
    """
    Plot a finite element mesh as a wireframe.
    """
    dim = coors.shape[1]
    ax = _get_axes(ax, dim)
    coors = _to2d(coors)

    for el in conn:
        eds = el[edges]

        for ed in eds:
            cc = coors[ed]

            ax.plot(*cc.T, color=color, **plot_kwargs)

    return ax

def plot_global_dofs(ax, coors, econn):
    """
    Plot global DOF numbers given in an extended connectivity.
{'fraction_non_alphanumeric': 0.10815199740175381, 'fraction_numerical': 0.013640792465086067, 'mean_word_length': 2.3441910966340935, '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': '5806985', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1055, 'n_words': 315}