Ejemplo n.º 1
0
    def plot_data(self,
                  data,
                  outPath="3-D_figure",
                  marker='sphere',
                  size=2,
                  heatmap=None,
                  inline=False,
                  plot_type="scatter"):

        ipv.figure(width=400, height=500, lighting=True, controls=True)
        x, y, z = data[0], data[1], data[2]
        #TODO: marker control
        if heatmap == None:
            if plot_type == "scatter":
                ipv.quickscatter(x, y, z, marker=marker,
                                 size=size)  #, size=10)
            if plot_type == "surface":
                ipv.plot_surface(x, y, z)
        else:
            from matplotlib import cm
            colormap = cm.coolwarm
            heatmap /= (heatmap - heatmap.min())
            color = colormap(heatmap)
            if plot_type == "scatter":
                ipv.quickscatter(x,
                                 y,
                                 z,
                                 color=color[..., :3],
                                 marker=marker,
                                 size=size)  #, size=10)
            if plot_type == "surface":
                ipv.plot_surface(x, y, z, color=color)

        #ipv.plot_surface(data[0], data[1], data[2], color="orange")
        #ipv.plot_wireframe(data[0], data[1], data[2], color="red")
        ipv.pylab.xlim(self.xlim[0], self.xlim[1])
        ipv.pylab.ylim(self.ylim[0], self.ylim[1])
        if self.zlim != [None, None]:
            ipv.pylab.zlim(self.zlim[0], self.zlim[1])
        else:
            ipv.pylab.zlim(self.ylim[0], self.ylim[1])
        #ipv.style.use(['seaborn-darkgrid', {'axes.x.color':'orange'}])
        ipv.pylab.view(azimuth=-45, elevation=25, distance=5)
        ipv.pylab.xlabel("%s" % self.axis_labels[0])
        ipv.pylab.ylabel("%s" % self.axis_labels[1])
        ipv.pylab.zlabel("%s" % self.axis_labels[2])
        if inline:
            ipv.show()
        else:
            ipv.pylab.save("%s.html" % outPath,
                           title=r"%s" % (latex),
                           offline=None,
                           template_options=(('extra_script_head', ''),
                                             ('body_pre', ''), ('body_post',
                                                                '')))
            run_cmd('open %s.html' % (str(outPath)))
Ejemplo n.º 2
0
def test_quick():
    x, y, z = ipyvolume.examples.xyz()
    p3.volshow(x*y*z)
    ipyvolume.quickvolshow(x*y*z, lighting=True)
    ipyvolume.quickvolshow(x*y*z, lighting=True, level=1, opacity=1, level_width=1)


    x, y, z, u, v, w = np.random.random((6, 100))
    ipyvolume.quickscatter(x, y, z)
    ipyvolume.quickquiver(x, y, z, u, v, w)
Ejemplo n.º 3
0
def _get_ipyvolume_app():
    # pylint: disable=invalid-name, no-member
    x, y, z = np.random.random((3, 1000))
    ipv.quickscatter(x, y, z, size=1, marker="sphere")
    ipv_plot = ipv.current.figure
    ipv_plot.width = 600
    ipv_plot.height = 600

    def randomize(_):
        x, y, z = np.random.random((3, 1000))
        scatter = ipv_plot.scatters[0]
        with ipv_plot.hold_sync():
            scatter.x = x
            scatter.y = y
            scatter.z = z

    ip_randomize = ipw.Button(description="Randomize")
    ip_randomize.on_click(randomize)

    return ipw.VBox([ip_randomize, ipv_plot])
Ejemplo n.º 4
0
    def render(self, resp: requests.models.Response) -> Widget:
        "Return an ipyvolume widget with the data object rendered on it."

        f = io.BytesIO(resp.content)
        points = pd.read_csv(f, delim_whitespace=True)
        # points = points[:: 300] # FIXME: use down-sampling here
        x = points.iloc[:, 0].values
        y = points.iloc[:, 1].values
        z = points.iloc[:, 2].values
        res = ipyvolume.quickscatter(x, y, z, size=1, marker="sphere")

        return res
Ejemplo n.º 5
0
def scatter(coords, color='gray'):
    """
    Use jupyter notebook to visualize point clouds.
    :param coords: [N, 3] numpy array with x, y, z coordinates
    :param color: color of points as string, e.g. 'red', '#ff0000' or 'rgb(1, 0, 0)'
    :return:
    """
    xs = coords[:, 0].astype(np.float)
    ys = coords[:, 1].astype(np.float)
    zs = coords[:, 2].astype(np.float)

    fig = ipv.quickscatter(xs, ys, zs, size=0.1, marker='sphere', color=color)
    ipv.pylab.style.use(axis_off)
    return fig
Ejemplo n.º 6
0
def scatter_with_intensities(coords, intensities):
    """
    Use jupyter notebook to visualize point clouds.
    :param coords: [N, 3] numpy array with x, y, z coordinates
    :param intensities [N] numpy array with corresponding intensities
    :return:
    """
    xs = coords[:, 0].astype(np.float)
    ys = coords[:, 1].astype(np.float)
    zs = coords[:, 2].astype(np.float)

    cs = list(map(lambda i: (1, 1 - i, 0), intensities))

    fig = ipv.quickscatter(xs, ys, zs, size=0.1, marker='sphere', color=cs)
    ipv.pylab.style.use(axis_off)
    ipv.pylab.view(200, 80)
    return fig
Ejemplo n.º 7
0
def scatter_with_target(coords,
                        target,
                        color=(0.5, 0.5, 0.5),
                        color_label=(1, 0, 0)):
    """
    Use jupyter notebook to visualize point clouds with an annotated item.
    :param coords: [N, 3] numpy array with x, y, z coordinates
    :param target: [N] binary numpy array with 0 for background and 1 for label
    :param color: color of points as rgb tuple, e.g. (1, 0, 0) for red
    :param color_label: color of labelled points as rgb tuple, e.g. (1, 0, 0) for red
    :return:
    """
    xs = coords[:, 0].astype(np.float)
    ys = coords[:, 1].astype(np.float)
    zs = coords[:, 2].astype(np.float)

    c = np.full_like(target, color, dtype=(float, 3))
    c[np.argwhere(target == 1)] = color_label

    fig = ipv.quickscatter(xs, ys, zs, size=0.1, marker='sphere', color=c)
    ipv.pylab.style.use(axis_off)
    ipv.pylab.view(200, 80)
    return fig
Ejemplo n.º 8
0
import ipyvolume as ipv
import ipywidgets as ipw
import numpy as np
from ipywidgets_bokeh import IPyWidget

from bokeh.layouts import column, row
from bokeh.models import Slider
from bokeh.plotting import curdoc

x, y, z = np.random.random((3, 1000))
ipv.quickscatter(x, y, z, size=1, marker="sphere")
plot = ipv.current.figure

x_slider = Slider(start=0, end=359, value=0, step=1, title="X-axis")
y_slider = Slider(start=0, end=359, value=0, step=1, title="Y-axis")
z_slider = Slider(start=0, end=359, value=0, step=1, title="Z-axis")


def randomize(button):
    x, y, z = np.random.random((3, 1000))
    scatter = plot.scatters[0]
    with plot.hold_sync():
        scatter.x = x
        scatter.y = y
        scatter.z = z


randomize_button = ipw.Button(description="Randomize")
randomize_button.on_click(randomize)