Exemplo n.º 1
0
    def test_doc_03(self):
        import vtkplotlib as vpl
        from stl.mesh import Mesh

        mesh = Mesh.from_file(vpl.data.get_rabbit_stl())
        vertices = mesh.vectors

        vpl.plot(vertices, join_ends=True, color="dark red")
Exemplo n.º 2
0
    def test_doc_04(self):
        import vtkplotlib as vpl
        import numpy as np

        # Create an octagon, using `t` as scalar values.
        t = np.arange(0, 1, .125) * 2 * np.pi
        vertices = vpl.zip_axes(np.cos(t), np.sin(t), 0)

        # Plot the octagon.
        vpl.plot(
            vertices,
            line_width=6,  # use a chunky (6pt) line
            join_ends=True,  # join the first and last points
            color=t,  # use `t` as scalar values to color it
        )

        # use a dark background for contrast
        fig = vpl.gcf()
        fig.background_color = "grey"
Exemplo n.º 3
0
    def test_multi_figures(self):
        vpl.close()

        vpl.auto_figure(False)

        plot = vpl.plot(np.random.uniform(-10, 10, (10, 3)), join_ends=True)
        figs = []
        for i in range(1, 4):
            fig = vpl.figure("figure {}".format(i))
            fig += plot
            vpl.view(camera_direction=np.random.uniform(-1, 1, 3), fig=fig)
            vpl.reset_camera(fig)

            fig.show(False)
            figs.append(fig)
        fig.show()

        vpl.auto_figure(True)
Exemplo n.º 4
0
def test_plot():
    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 = vpl.zip_axes(np.cos(t), np.sin(t), 0)

    # vertices = np.random.uniform(-30, 30, (3, 3))
    # color = np.broadcast_to(t, vertices.shape[:-1])

    self = vpl.plot(vertices, line_width=6, join_ends=True, color=t)
    # self.polydata.point_scalars = vpl.geometry.distance(vertices)
    # self.polydata.point_colors = t
    fig = vpl.gcf()
    fig.background_color = "grey"
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
0
def test_legend():
    import vtkplotlib as vpl

    self = vpl.legend(None, fig=None)
    assert self.fig is None
    assert self.length == 0
    vpl.gcf().add_plot(self)

    self.set_entry(label="Blue Square", color="blue")

    sphere = vpl.scatter([0, 5, 10], color="g", fig=None, label="Ball")
    self.set_entry(sphere, color="b")
    self.set_entry(
        sphere,
        "Green ball",
    )

    rabbit = vpl.mesh_plot(vpl.data.get_rabbit_stl())
    self.set_entry(rabbit, "rabbit")

    rabbit_wire = vpl.plot(rabbit.vectors,
                           color=rabbit.vectors[:, :, 0],
                           label="octopus")
    self.set_entry(rabbit_wire)
    assert self.legend.GetEntryString(self.length - 1) == "octopus"

    # self.set_entry(vpl.quiver(np.zeros(3), np.array([-1, 0, 1])), "right")
    self.set_entry(None, label="shark", icon=vpl.data.ICONS["Right"])

    for size in ((.3, .4), (.3, .4, 0)):
        self.size = size
        assert np.array_equal(self.size, [.3, .4, 0])

    position = np.array(1) - self.size
    self.position = position
    assert np.array_equal(self.position, position)

    with pytest.raises(TypeError):
        self.set_entry(object())

    length = self.length
    for i in range(2):
        eggs = vpl.text3d("eggs", label="eggs")
        self.add_plots([eggs])
        # Re-adding labels shouldn't cause the legend to grow
        assert self.length == length + 1

    vpl.text("text")

    auto_legend = vpl.legend(position=(0, 0))
    auto_legend_no_label = vpl.legend(position=(0, .7),
                                      allow_no_label=True,
                                      allow_non_polydata_plots=True,
                                      color=(.2, .3, .4, .5))
    assert auto_legend_no_label.color == (.2, .3, .4)
    assert auto_legend_no_label.opacity == .5

    self.set_entry(vpl.scatter(np.arange(12).reshape((-1, 3)),
                               label="scatter"),
                   label="fish",
                   index=self.length + 3)

    self.add_plots(vpl.gcf().plots)