def plot_indices(mis, dims=None, weights=None, groups=<NUM_LIT:1>,legend = True,index_labels=None, colors = None,axis_labels = None,size_exponent=<NUM_LIT:0.1>,ax=None):
if weights is None:<EOL><INDENT>weights = {mi: <NUM_LIT:1> for mi in mis}<EOL><DEDENT>if Function.valid(weights):<EOL><INDENT>weights = {mi:weights(mi) for mi in mis}<EOL><DEDENT>values = list(weights.values())<EOL>if Integer.valid(groups):<EOL><INDENT>N_g = groups<EOL>groups = [[mi for mi in mis if (weights[mi] > np.percentile(values, <NUM_LIT:100>/groups*g) or g==<NUM_LIT:0>) and weights[mi] <= np.percentile(values, <NUM_LIT:100>/groups*(g+<NUM_LIT:1>))] for g in range(N_g)]<EOL>group_names = ['<STR_LIT>'.format(<NUM_LIT:100>/N_g*(N_g-i-<NUM_LIT:1>),<NUM_LIT:100>/N_g*(N_g-i)) for i in reversed(range(N_g))]<EOL><DEDENT>else:<EOL><INDENT>if Function.valid(groups):<EOL><INDENT>groups = {mi:groups(mi) for mi in mis}<EOL><DEDENT>group_names = unique(list(groups.values()))<EOL>groups = [[mi for mi in mis if groups[mi]==name] for name in group_names]<EOL>N_g = len(group_names)<EOL><DEDENT>if colors is None: <EOL><INDENT>colors = matplotlib.cm.rainbow(np.linspace(<NUM_LIT:0>, <NUM_LIT:1>, N_g))  <EOL><DEDENT>if Dict.valid(mis):<EOL><INDENT>if index_labels is None or weights is None:<EOL><INDENT>temp = list(mis.keys())<EOL>if (List|Tuple).valid(temp[<NUM_LIT:0>]):<EOL><INDENT>if not (index_labels is None and weights is None):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>weights = {mi:mis[mi][<NUM_LIT:0>] for mi in mis}<EOL>index_labels=  {mi:mis[mi][<NUM_LIT:1>] for mi in mis}<EOL><DEDENT>else:<EOL><INDENT>if weights is None:<EOL><INDENT>weights = mis<EOL><DEDENT>else:<EOL><INDENT>index_labels = mis<EOL><DEDENT><DEDENT>mis = temp<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>if dims is None:<EOL><INDENT>try:<EOL><INDENT>dims = len(mis[<NUM_LIT:0>])<EOL><DEDENT>except TypeError:<EOL><INDENT>dims = sorted(list(set.union(*(set(mi.active_dims()) for mi in mis))))   <EOL><DEDENT><DEDENT>if len(dims) > <NUM_LIT:3>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if len(dims) < <NUM_LIT:1>:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>return<EOL><DEDENT>if ax is None:<EOL><INDENT>fig = plt.figure() <EOL>if len(dims) == <NUM_LIT:3>:<EOL><INDENT>ax = fig.gca(projection='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>ax = fig.gca()<EOL><DEDENT><DEDENT>size_function = lambda mi: sum([weights[mi2] for mi2 in mis if mi.equal_mod(mi2, lambda dim: dim not in dims)]) <EOL>sizes = {mi: np.power(size_function(mi), size_exponent) for mi in mis}<EOL>for i,plot_indices in enumerate(groups):<EOL><INDENT>X = np.array([mi[dims[<NUM_LIT:0>]] for mi in plot_indices])<EOL>if len(dims) > <NUM_LIT:1>:<EOL><INDENT>Y = np.array([mi[dims[<NUM_LIT:1>]] for mi in plot_indices])<EOL><DEDENT>else:<EOL><INDENT>Y = np.array([<NUM_LIT:0> for mi in plot_indices])<EOL><DEDENT>if len(dims) > <NUM_LIT:2>:<EOL><INDENT>Z = np.array([mi[dims[<NUM_LIT:2>]] for mi in plot_indices])<EOL><DEDENT>else:<EOL><INDENT>Z = np.array([<NUM_LIT:0> for mi in plot_indices])   <EOL><DEDENT>sizes_plot = np.array([sizes[mi] for mi in plot_indices])<EOL>if weights:<EOL><INDENT>if len(dims) == <NUM_LIT:3>:<EOL><INDENT>ax.scatter(X, Y, Z, s = <NUM_LIT:50> * sizes_plot / max(sizes.values()), color=colors[i], alpha=<NUM_LIT:1>)            <EOL><DEDENT>else:<EOL><INDENT>ax.scatter(X, Y, s = <NUM_LIT:50> * sizes_plot / max(sizes.values()), color=colors[i], alpha=<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if len(dims) == <NUM_LIT:3>:<EOL><INDENT>ax.scatter(X, Y, Z,color = colors[i],alpha=<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>ax.scatter(X, Y,color=colors[i],alpha=<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if True:<EOL><INDENT>if len(dims)==<NUM_LIT:3>:<EOL><INDENT>axs='<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>axs='<STR_LIT>'<EOL><DEDENT>extents = np.array([getattr(ax, '<STR_LIT>'.format(dim))() for dim in axs])<EOL>sz = extents[:,<NUM_LIT:1>] - extents[:,<NUM_LIT:0>]<EOL>maxsize = max(abs(sz))<EOL>for dim in axs:<EOL><INDENT>getattr(ax, '<STR_LIT>'.format(dim))(<NUM_LIT:0>, maxsize)<EOL><DEDENT><DEDENT><DEDENT>if axis_labels is not None:<EOL><INDENT>ax.set_xlabel(axis_labels[<NUM_LIT:0>])<EOL>if len(dims)><NUM_LIT:1>:<EOL><INDENT>ax.set_ylabel(axis_labels[<NUM_LIT:1>])<EOL><DEDENT>if len(dims)><NUM_LIT:1>:<EOL><INDENT>ax.set_zlabel(axis_labels[<NUM_LIT:2>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>ax.set_xlabel('<STR_LIT>' + str(dims[<NUM_LIT:0>])+'<STR_LIT:$>',size=<NUM_LIT:20>)<EOL>if len(dims) > <NUM_LIT:1>:<EOL><INDENT>ax.set_ylabel('<STR_LIT>' + str(dims[<NUM_LIT:1>])+'<STR_LIT:$>',size=<NUM_LIT:20>)<EOL><DEDENT>if len(dims) > <NUM_LIT:2>:<EOL><INDENT>ax.set_zlabel('<STR_LIT>' + str(dims[<NUM_LIT:2>])+'<STR_LIT:$>',size=<NUM_LIT:20>)<EOL><DEDENT>plt.grid()<EOL><DEDENT>x_coordinates = [mi[dims[<NUM_LIT:0>]] for mi in mis]<EOL>xticks=list(range(min(x_coordinates),max(x_coordinates)+<NUM_LIT:1>))<EOL>ax.set_xticks(xticks)<EOL>if len(dims)><NUM_LIT:1>:<EOL><INDENT>y_coordinates = [mi[dims[<NUM_LIT:1>]] for mi in mis]<EOL>ax.set_yticks(list(range(min(y_coordinates),max(y_coordinates)+<NUM_LIT:1>)))<EOL><DEDENT>if len(dims)><NUM_LIT:2>:<EOL><INDENT>z_coordinates = [mi[dims[<NUM_LIT:2>]] for mi in mis]<EOL>ax.set_zticks(list(range(min(z_coordinates),max(z_coordinates)+<NUM_LIT:1>)))<EOL><DEDENT>if index_labels:<EOL><INDENT>for mi in index_labels:<EOL><INDENT>ax.annotate('<STR_LIT>'.format(index_labels[mi]),xy=(mi[<NUM_LIT:0>],mi[<NUM_LIT:1>]))<EOL><DEDENT><DEDENT>if legend and len(group_names)><NUM_LIT:1>:<EOL><INDENT>ax.legend([patches.Patch(color=color) for color in np.flipud(colors)],group_names)<EOL><DEDENT>return ax<EOL>
Plot multi-index set

:param mis: Multi-index set
:type mis: Iterable of SparseIndices
:param dims: Which dimensions to use for plotting
:type dims: List of integers.
:param weights: Weights associated with each multi-index
:type weights: Dictionary
:param quantiles: Number of groups plotted in different colors
:type quantiles: Integer>=1 or list of colors

TODO: exchange index_labels and dims, exchange quantiles and dims