def test_doc_035(self): import numpy as np # Define the 2 independent variables phi, theta = np.meshgrid(np.linspace(0, 2 * np.pi, 1024), np.linspace(0, np.pi, 1024)) # Calculate the x, y, z values to form a sphere x = np.cos(phi) * np.sin(theta) y = np.sin(phi) * np.sin(theta) z = np.cos(theta) # You can play around with this. The coordinates must be zipped # together into one array with ``shape[-1] == 2``, hence the # ``vpl.zip_axes``. And must be between 0 and 1, hence the ``% 1.0``. texture_coords = (vpl.zip_axes(phi * 3, theta * 5) / np.pi) % 1.0 # Pick an image to use. There is a picture of a shark here if you # don't have one available. path = vpl.data.ICONS["Right"] texture_map = vpl.TextureMap(path, interpolate=True) # You could convert ``texture_coords`` to ``colors`` now using. # colors = texture_map(texture_coords) # then pass ``colors`` as the `scalars` argument instead. vpl.surface(x, y, z, scalars=texture_coords, texture_map=texture_map)
def test_texture(): 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.connect() vpl.gcf().add_plot(self)
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"
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"
:param label: Give the plot a label to use in legends, defaults to None. :type label: str, optional :return: arrow or array of arrows :rtype: vtkplotlib.plots.Arrow.Arrow, np.array of Arrows .. seealso:: ``vpl.arrow`` to draw arrows from a start point to an end point. """ 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, label) if __name__ == "__main__": import vtkplotlib as vpl t = np.linspace(0, 2 * np.pi) points = vpl.zip_axes([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()
def test_doc_14(self): import numpy as np vpl.zip_axes(np.arange(10), 4, np.arange(-5, 5))