# Path: megaman/plotter/utils.py
# def _check_backend(backend):
#     def decorator(func):
#         def wrapper(*args,**kwargs):
#             import warnings
#             warnings.warn(
#                 'Be careful in using megaman.plotter modules'
#                 ' API will change in the next release.',
#                 FutureWarning
#             )
#             import pkgutil
#             package = pkgutil.find_loader(backend)
#             if package is not None:
#                 return func(*args,**kwargs)
#             else:
#                 raise ImportError('plotting backend {} not installed'.format(backend))
#         return wrapper
#     return decorator


import numpy as np
        import matplotlib.pyplot as plt
            import warnings
    import plotly.graph_objs as go
from .utils import _check_backend
    from mpl_toolkits.mplot3d import art3d, Axes3D
            warnings.warn(
                'Subplot grid is not provided, switching to non-subplot mode')
        ax = fig.gca(projection='3d')

    ax.set_aspect('equal')
    s = [2 for i in range(embedding.shape[0])]
    x,y,z = embedding[:,:3].T

    if isinstance(coloring, str) and coloring.lower() in 'xyz':
        color_idx = 'xyz'.find(coloring)
        coloring = embedding[:,color_idx].flatten()

    if coloring is None:
        ax.scatter(x,y,z,s=s,**kwargs)
    else:
        sc = ax.scatter(x,y,z,c=coloring,cmap='gist_rainbow',s=s,**kwargs)
        fig.colorbar(sc)

    max_range = np.array(
        [x.max()-x.min(), y.max()-y.min(), z.max()-z.min()]).max() / 2.0

    mid_x = (x.max()+x.min()) * 0.5
    mid_y = (y.max()+y.min()) * 0.5
    mid_z = (z.max()+z.min()) * 0.5
    ax.set_xlim(mid_x - max_range, mid_x + max_range)
    ax.set_ylim(mid_y - max_range, mid_y + max_range)
    ax.set_zlim(mid_z - max_range, mid_z + max_range)

    return fig, ax


# Path: megaman/plotter/utils.py
# def _check_backend(backend):
#     def decorator(func):
#         def wrapper(*args,**kwargs):
#             import warnings
#             warnings.warn(
#                 'Be careful in using megaman.plotter modules'
#                 ' API will change in the next release.',
#                 FutureWarning
#             )
#             import pkgutil
#             package = pkgutil.find_loader(backend)
#             if package is not None:
#                 return func(*args,**kwargs)
#             else:
#                 raise ImportError('plotting backend {} not installed'.format(backend))
#         return wrapper
#     return decorator


# Path: megaman/plotter/scatter_3d.py
import numpy as np
        import matplotlib.pyplot as plt
            import warnings
    import plotly.graph_objs as go
from .utils import _check_backend
    from mpl_toolkits.mplot3d import art3d, Axes3D

            warnings.warn(
                'Subplot grid is not provided, switching to non-subplot mode')
        ax = fig.gca(projection='3d')

    ax.set_aspect('equal')
    s = [2 for i in range(embedding.shape[0])]
    x,y,z = embedding[:,:3].T

    if isinstance(coloring, str) and coloring.lower() in 'xyz':
        color_idx = 'xyz'.find(coloring)
        coloring = embedding[:,color_idx].flatten()

    if coloring is None:
        ax.scatter(x,y,z,s=s,**kwargs)
    else:
        sc = ax.scatter(x,y,z,c=coloring,cmap='gist_rainbow',s=s,**kwargs)
        fig.colorbar(sc)

    max_range = np.array(
        [x.max()-x.min(), y.max()-y.min(), z.max()-z.min()]).max() / 2.0

    mid_x = (x.max()+x.min()) * 0.5
    mid_y = (y.max()+y.min()) * 0.5
    mid_z = (z.max()+z.min()) * 0.5
    ax.set_xlim(mid_x - max_range, mid_x + max_range)
    ax.set_ylim(mid_y - max_range, mid_y + max_range)
    ax.set_zlim(mid_z - max_range, mid_z + max_range)

    return fig, ax


@_check_backend('plotly')