コード例 #1
0
    def test_quiver(self):
        t = np.linspace(0, 2 * np.pi)
        points = np.array([np.cos(t), np.sin(t), np.cos(t) * np.sin(t)]).T
        grads = np.roll(points, 10)

        arrows = vpl.quiver(points, grads, color=grads)
        self.assertEqual(arrows.shape, t.shape)

        vpl.show()
コード例 #2
0
def test():
    from stl.mesh import Mesh
    import vtkplotlib as vpl

    mesh = Mesh.from_file(vpl.data.get_rabbit_stl())
    plot = vpl.mesh_plot(mesh, scalars=mesh.x)

    vpl.scalar_bar(plot)

    vpl.show()
コード例 #3
0
    def quick_show(self):
        import vtkplotlib as vpl
        old_fig = vpl.gcf(create_new=False)

        fig = vpl.figure(repr(self))
        plot = self.to_plot(fig)
        vpl.show(fig)

        vpl.scf(old_fig)
        return plot
コード例 #4
0
    def test_surface(self):
        thi, theta = np.meshgrid(np.linspace(0, 2 * np.pi, 100),
                                 np.linspace(0, np.pi, 50))

        x = np.cos(thi) * np.sin(theta)
        y = np.sin(thi) * np.sin(theta)
        z = np.cos(theta)

        vpl.surface(x, y, z, scalars=x.ravel()).set_scalar_range()
        vpl.show()
コード例 #5
0
def test():

    import vtkplotlib as vpl

    t = np.arange(0, 1, .1) * 2 * np.pi
    points = np.array([np.cos(t), np.sin(t), np.cos(t) * np.sin(t)]).T

    self = vpl.polygon(points, color="r")

    vpl.show()
コード例 #6
0
    def test_qfigure(self):
        fig = vpl.QtFigure("a qt widget figure")

        self.assertIs(fig, vpl.gcf())

        direction = np.array([1, 0, 0])
        vpl.quiver(np.array([0, 0, 0]), direction)
        vpl.view(camera_direction=direction)
        vpl.reset_camera()

        vpl.show()
コード例 #7
0
def test():
    import vtkplotlib as vpl

    #    self = vpl.text3d("some text", follow_cam=True)

    point = np.array([1, 2, 3])
    vpl.scatter(point)

    arrow, text = vpl.annotate(point, point, np.array([0, 0, 1]))

    globals().update(locals())

    vpl.show()
コード例 #8
0
def test_view():
    vpl.auto_figure(True)
    vpl.close()
    grads = np.array(vpl.geometry.orthogonal_bases(np.random.rand(3)))
    point = np.random.uniform(-10, 10, 3)
    vpl.quiver(np.broadcast_to(point, (3, 3)), grads, color=np.eye(3))

    vpl.view(focal_point=point, camera_position=point - grads[0],
             up_view=grads[1])
    vpl.reset_camera()

    vpl.text("Should be looking in the direction of the red arrow, "
             "with the green arrow pointing up")
    # Linux seems to need an extra prod to render this for some reason.
    vpl.show(block=False)
コード例 #9
0
def test():
    import vtkplotlib as vpl

    phi, theta = np.meshgrid(np.linspace(0, 2 * np.pi, 1024),
                             np.linspace(0, np.pi, 1024))

    x = np.cos(phi) * np.sin(theta)
    y = np.sin(phi) * np.sin(theta)
    z = np.cos(theta)

    self = vpl.surface(x, y, z, fig=None)
    path = vpl.data.ICONS["Right"]
    self.polydata.texture_map = vpl.TextureMap(path, interpolate=True)
    self.colors = (vpl.zip_axes(phi * 3, theta * 5) / np.pi) % 1.

    self.add_to_plot()
    vpl.gcf().add_plot(self)
    vpl.show()
コード例 #10
0
def test():
    import vtkplotlib as vpl

    t = np.arange(0, 1, .001) * 2 * np.pi
    vertices = np.array([np.cos(2 * t),
                         np.sin(3 * t),
                         np.cos(5 * t) * np.sin(7 *t)]).T
    vertices = np.array([vertices, vertices + 2])

    t = np.arange(0, 1, .125) * 2 * np.pi
    vertices = np.array([np.cos(t), np.sin(t), np.zeros_like(t)]).T

#    vertices = np.random.uniform(-30, 30, (3, 3))
    self = vpl.plot(vertices, color="green", line_width=6, join_ends=True)
#    self.polydata.point_scalars = vpl.geometry.distance(vertices)
    self.polydata.point_scalars = t
    fig = vpl.gcf()
    fig.background_color = "grey"
    self.add_to_plot()
    vpl.show()
コード例 #11
0
    def test_view(self):
        vpl.auto_figure(True)
        vpl.close()
        grads = np.array(vpl.geometry.orthogonal_bases(np.random.rand(3)))
        point = np.random.uniform(-10, 10, 3)
        vpl.quiver(np.broadcast_to(point, (3, 3)), grads, color=np.eye(3))

        vpl.view(focal_point=point,
                 camera_position=point - grads[0],
                 up_view=grads[1])
        #        vpl.view(camera_direction=grads[0],
        #                 up_view=grads[1],
        #                 )
        #
        vpl.reset_camera()
        #        vpl.view(point)

        vpl.text(
            "Should be looking in the direction of the red arrow, with the green arrow pointing up"
        )
        vpl.show()
コード例 #12
0
    def test_save(self):
        plots = vpl.scatter(np.random.uniform(-10, 10, (30, 3)))

        # I can't get python2 to cooperate with unicode here.
        # The os functions just don't like them.
        if sys.version[0] == "3":

            path = Path.cwd() / u"ҢघԝઌƔࢳܢˀા\\Հએࡓ\u061cཪЈतயଯ\u0886.png"
            try:
                os.mkdir(str(path.parent))
                vpl.save_fig(path)
                self.assertTrue(path.exists())
                os.remove(str(path))
            finally:
                if path.parent.exists():
                    os.rmdir(str(path.parent))

        else:
            path = Path.cwd() / "image.png"
            vpl.save_fig(path)
            os.remove(str(path))

        array = vpl.screenshot_fig(2)
        self.assertEqual(array.shape,
                         tuple(i * 2 for i in vpl.gcf().render_size) + (3, ))
        plt.imshow(array)
        plt.show()

        shape = tuple(i * j for (i, j) in zip(vpl.gcf().render_size, (2, 3)))
        vpl.screenshot_fig(pixels=shape).shape
        # The following will fail depending on VTK version
        #        self.assertEqual(vpl.screenshot_fig(pixels=shape).shape,
        #                         shape[::-1] + (3,))

        vpl.close()
        fig = vpl.figure()
        for plot in plots:
            fig += plot
        vpl.show()
コード例 #13
0
def test():
    import vtkplotlib as vpl

    points = np.random.uniform(-10, 10, (30, 3))

    #    for i in range(3):
    #        self = vpl.cursor(np.array([5, 0, 0]) * i, radius=4)

    colors = vpl.colors.normalise(points)
    radii = np.abs(points[:, 0])**.5

    vpl.scatter(
        points,
        color=colors,
        radius=radii,
        use_cursors=False,
    )[0]
    self = vpl.scatter(points, color=colors, radius=radii, use_cursors=True)[0]
    #    self.point += np.array([10, 0, 0])

    globals().update(locals())

    vpl.show()
コード例 #14
0
    :param fig: The figure to plot into, can be None, defaults to vpl.gcf().
    :type fig: vpl.figure, vpl.QtFigure


    :return: arrow or array of arrows
    :rtype: vtkplotlib.plots.Arrow.Arrow, np.array of Arrows

    """

    if length is None:
        length = geom.distance(gradient)
    if length_scale != 1:
        length *= length_scale

    return arrow(point, point + gradient, length, width_scale, color, opacity,
                 fig)


if __name__ == "__main__":

    import vtkplotlib as vpl

    t = np.linspace(0, 2 * np.pi)
    points = np.array([np.cos(t), np.sin(t), np.cos(t) * np.sin(t)]).T
    grads = np.roll(points, 10)

    arrows = quiver(points, grads, width_scale=.3, color=grads)

    vpl.show()
コード例 #15
0
 def test_text(self):
     vpl.text("text", (100, 100), color="g")
     vpl.show()
コード例 #16
0
    def test_plot(self):
        t = np.arange(0, 1, .1) * 2 * np.pi
        points = np.array([np.cos(t), np.sin(t), np.cos(t) * np.sin(t)]).T
        vpl.plot(points, color="r", line_width=3, join_ends=True)

        vpl.show()
コード例 #17
0
 def test_arrow(self):
     points = np.random.uniform(-10, 10, (2, 3))
     vpl.scatter(points)
     vpl.arrow(*points, color="g")
     vpl.show()
コード例 #18
0
ファイル: test_figures.py プロジェクト: draked2/vtkplotlib
def test_zoom():
    vpl.scatter(np.random.uniform(-20, 20, (30, 3)), color="r")
    vpl.show(block=False)
    balls_to_ignore = vpl.scatter(np.random.uniform(-50, 50, (30, 3)))
    vpl.text("This should be ignored by zoom.")
    vpl.zoom_to_contents(plots_to_exclude=balls_to_ignore)