<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def plot_connections(network, throats=None, fig=None, **kwargs):
 r""" Produces a 3D plot of the network topology showing how throats connect for quick visualization without having to export data to veiw in Paraview. Parameters network : OpenPNM Network Object The network whose topological connections to plot throats : array_like (optional) The list of throats to plot if only a sub-sample is desired. This is useful for inspecting a small region of the network. If no throats are specified then all throats are shown. fig : Matplotlib figure handle and line property arguments If a ``fig`` is supplied, then the topology will be overlaid on this plot. This makes it possible to combine coordinates and connections, and to color different throats differently (see ``kwargs``) kwargs : other named arguments By also in different line properties such as ``color`` it's possible to plot several different sets of connections with unique colors. For information on available line style options, visit the Matplotlib documentation on the `web <http://matplotlib.org/api/lines_api.html#matplotlib.lines.Line2D>`_ Notes ----- The figure handle returned by this method can be passed into ``plot_coordinates`` to create a plot that combines pore coordinates and throat connections, and vice versa. See Also -------- plot_coordinates Examples -------- """

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D

    if throats is None:
        Ts = network.Ts
    else:
        Ts = network._parse_indices(indices=throats)

    if len(sp.unique(network['pore.coords'][:, 2])) == 1:
        ThreeD = False
    else:
        ThreeD = True

    if fig is None:
        fig = plt.figure()
        if ThreeD:
            ax = fig.add_subplot(111, projection='3d')
        else:
            ax = fig.gca()
    else:
        ax = fig.gca()

    # Create dummy indexing to sp.inf
    i = -1*sp.ones((sp.size(Ts)*3, ), dtype=int)
    i[0::3] = network['throat.conns'][Ts, 0]
    i[1::3] = network['throat.conns'][Ts, 1]

    # Collect coordinates and scale axes to fit
    Ps = sp.unique(network['throat.conns'][Ts])
    X = network['pore.coords'][Ps, 0]
    Y = network['pore.coords'][Ps, 1]
    Z = network['pore.coords'][Ps, 2]
    _scale_3d_axes(ax=ax, X=X, Y=Y, Z=Z)

    # Add sp.inf to the last element of pore.coords (i.e. -1)
    inf = sp.array((sp.inf,))
    X = sp.hstack([network['pore.coords'][:, 0], inf])
    Y = sp.hstack([network['pore.coords'][:, 1], inf])
    Z = sp.hstack([network['pore.coords'][:, 2], inf])
    if ThreeD:
        ax.plot(xs=X[i], ys=Y[i], zs=Z[i], **kwargs)
    else:
        ax.plot(X[i], Y[i], **kwargs)

    return fig