def ipv_plot_molecule(molecule):
    for atom_symbol in atom_symbols:
        atoms = [atom for atom in molecule.atoms if atom.symbol == atom_symbol]
        if len(atoms) == 0:
            continue

        x = np.array([atom.position[0] for atom in atoms])
        y = np.array([atom.position[1] for atom in atoms])
        z = np.array([atom.position[2] for atom in atoms])

        p3.scatter(x=x,
                   y=y,
                   z=z,
                   color=atom_color[atom_symbol],
                   size=atom_size[atom_symbol],
                   marker='sphere')

    for bond in molecule.bonds:
        p1 = bond.atom1.position
        p2 = bond.atom2.position
        p3.plot(x=np.array([p1[0], p2[0]]),
                y=np.array([p1[1], p2[1]]),
                z=np.array([p1[2], p2[2]]),
                color='black')
    p3.show()
예제 #2
0
def init_vector(show=True):
    #This function initializes a figure with basis vectors in world frame - requires import ipyvolume.pylab as p3 outside scope
    #p3.clear()
    origin = np.array([0.0, 0.0, 0.0])
    x = origin + np.array([1.0, 0.0, 0.0])
    y = origin + np.array([0.0, 1.0, 0.0])
    z = origin + np.array([0.0, 0.0, 1.0])
    u = np.array([1.0, 0.0, 0.0])
    v = np.array([0.0, 1.0, 0.0])
    w = np.array([0.0, 0.0, 1.0])
    quiver = p3.quiver(x,
                       y,
                       z,
                       u,
                       v,
                       w,
                       size=10,
                       marker='arrow',
                       color=np.array([[1, 0, 0], [0, 1, 0],
                                       [0, 0, 1]]))  #ipv.show()
    scatter = p3.scatter(np.array([origin[0]]),
                         np.array([origin[0]]),
                         np.array([origin[0]]),
                         size=5,
                         marker='sphere',
                         color='red')
    line1 = p3.plot(np.array([origin[0], x[0]]),
                    np.array([origin[0], x[1]]),
                    np.array([origin[0], x[2]]),
                    color='red')
    line2 = p3.plot(np.array([origin[0], y[0]]),
                    np.array([origin[0], y[1]]),
                    np.array([origin[0], y[2]]),
                    color='green')
    line3 = p3.plot(np.array([origin[0], z[0]]),
                    np.array([origin[0], z[1]]),
                    np.array([origin[0], z[2]]),
                    color='blue')
    #scatter = p3.scatter(x,y,z,size=2,marker = 'sphere',color='red') # the origin
    if show:
        p3.show()
        p3.style.box_off()
    handle = {
        'origin': scatter,
        'arrows': quiver,
        'linex': line1,
        'liney': line2,
        'linez': line3
    }
    #p3.style.axes_off()
    return handle
예제 #3
0
    def plot(self,
             width=800,
             height=600,
             voxel_count_offset=0,
             voxel_limit=None,
             use_centroids_instead=False,
             ipyvol_fig=None,
             scaling=1,
             **kwargs):
        """
        This method needs better documentation.

        :param **kwargs: Is used in ipyvolume.pylab.scatter() or ipyvolume.pylab.plot() depending on whether use_centroids_instead
        is set to true or not.
        """
        if ipyvol_fig is None:
            p3.figure(width=width, height=height)
        else:
            p3.figure(ipyvol_fig)
        voxels_length = len(self)
        if voxel_count_offset >= voxels_length:
            raise ValueError(
                "voxel_count_offset is greater than the number of voxels!")
        else:
            if voxel_limit is None:
                n_voxels_to_plot = len(self)
            else:
                n_voxels_to_plot = voxel_count_offset + voxel_limit
                if n_voxels_to_plot > voxels_length:
                    n_voxels_to_plot = len(self)

        if use_centroids_instead:
            if 'marker' not in kwargs:
                kwargs['marker'] = 'sphere'
            if 'color' not in kwargs:
                kwargs['color'] = 'blue'
            if 'size' not in kwargs:
                kwargs['size'] = 0.5
            p3.scatter(
                *self.centroids[voxel_count_offset:n_voxels_to_plot].T *
                scaling, **kwargs)
        else:
            voxel_count_offset *= 18
            n_voxels_to_plot *= 18
            drawable_bboxes = self.drawable_bboxes[
                voxel_count_offset:n_voxels_to_plot]
            p3.plot(*drawable_bboxes.T * scaling, **kwargs)

        p3.squarelim()
        p3.show()
예제 #4
0
# set ipyvolume style properties
p3.style.background_color('black')
p3.style.box_off()
p3.style.use("dark")
p3.style.use({'xaxis.color': "red"})  # <-+
p3.style.use({'yaxis.color': "green"})  # <-+- do not appear to be working
p3.style.use({'zaxis.color': "blue"})  # <-+

# set figure view and axes
p3.view(0.0, -120.0)
p3.xyzlim(-2.0, 2.0)
p3.xyzlabel('X', 'Y', 'Z')

# coordinate frame axes line segments
Lx = p3.plot(Xf[:, 0:2, 0], Yf[:, 0:2, 0], Zf[:, 0:2, 0], color='red', size=2)
Lx.material.visible = False
Lx.line_material.visible = True
Ly = p3.plot(Xf[:, 0:2, 1], Yf[:, 0:2, 1], Zf[:, 0:2, 1], color='green')
Ly.material.visible = False
Ly.line_material.visible = True
Lz = p3.plot(Xf[:, 0:2, 2], Yf[:, 0:2, 2], Zf[:, 0:2, 2], color='blue')
Lz.material.visible = False
Lz.line_material.visible = True

# coordinate frame axes line segment tip arrows
Xfv = Xf[:, 1, :] - Xf[:, 0, :]
Yfv = Yf[:, 1, :] - Yf[:, 0, :]
Zfv = Zf[:, 1, :] - Zf[:, 0, :]
arrowcols = np.zeros((k, 3, 3))
arrowcols[0:k, 0, 0] = 1.0
예제 #5
0
def test_plot():
    x, y, z = np.random.random((3, 100))
    p3.plot(x, y, z)
    p3.save("tmp/ipyolume_plot.html")
예제 #6
0
def plot_skeleton_3d(skeleton, color='blue', *, client=None):
    """
    Plot the given skeleton in 3D.

    Args:
        skeleton:
            Either a bodyId or a pre-fetched pandas DataFrame

        color:
            See ``ipyvolume`` docs.
            Examples: ``'blue'``, ``'#0000ff'``
            If the skeleton is fragmented, you can give a list
            of colors and each fragment will be shown in a
            different color.

    Requires ``ipyvolume``.
    If using Jupyterlab, install it like this:

    .. code-block: bash

        conda install -c conda-forge ipyvolume
        jupyter labextension install ipyvolume
    """
    import ipyvolume.pylab as ipv

    if np.issubdtype(type(skeleton), np.integer):
        skeleton = client.fetch_skeleton(skeleton, format='pandas')

    assert isinstance(skeleton, pd.DataFrame)
    g = skeleton_df_to_nx(skeleton)

    def skel_path(root):
        """
        We want to plot each skeleton fragment as a single continuous line,
        but that means we have to backtrack: parent -> leaf -> parent
        to avoid jumping from one branch to another.
        This means that the line will be drawn on top of itself,
        and we'll have 2x as many line segments in the plot,
        but that's not a big deal.
        """
        def accumulate_points(n):
            p = (g.nodes[n]['x'], g.nodes[n]['y'], g.nodes[n]['z'])
            points.append(p)

            children = [*g.successors(n)]
            if not children:
                return
            for c in children:
                accumulate_points(c)
                points.append(p)

        points = []
        accumulate_points(root)
        return np.asarray(points)

    # Skeleton may contain multiple fragments,
    # so compute the path for each one.
    def skel_paths(df):
        paths = []
        for root in df.query('link == -1')['rowId']:
            paths.append(skel_path(root))
        return paths

    paths = skel_paths(skeleton)
    if isinstance(color, str):
        colors = len(paths) * [color]
    else:
        colors = (1 + len(paths) // len(color)) * color

    ipv.figure()
    for points, color in zip(paths, colors):
        ipv.plot(*points.transpose(), color)
    ipv.show()
예제 #7
0
%pylab inline
import ipyvolume as ipv
import ipyvolume.pylab as p3
import numpy as np
import rebound
from rebound import hash as h

from astropy.io import ascii

p3.clear()
##Location of npz files produced by other script
loc="./"
x=np.load(loc+'x.npz')
y=np.load(loc+'y.npz')
z=np.load(loc+'z.npz')

s2=p3.plot(x['arr_0'], y['arr_0'], z['arr_0'])
# s3=p3.plot(x['arr_0'][:, 1, :], y['arr_0'][:, 1, :], z['arr_0'][:, 1, :], color='red', size=0.3, alpha='0.5')

ipv.pylab.xlim(-1,1)
ipv.pylab.ylim(-1,1)
ipv.pylab.zlim(-1,1)
ipv.pylab.view(azimuth=None, elevation=-90, distance=1.5)

p3.show()
ipv.animation_control(s2)