<jupyter_start><jupyter_text>Adding objects to plotIn this example we will draw a simple 3D primitive, add it to the plot,and display the result.To draw the triangle we will use the `mesh()` method from the `k3d` module.This method creates a `Mesh` object, which can be added to a K3D `Plot`.<jupyter_code>import k3d
plot = k3d.plot()


vertices = [[0, 0, 0], [0, 0, 1], [1, 0, 0]]
indices = [[0, 1, 2]]

mesh = k3d.mesh(vertices, indices)

plot += mesh

plot.display()<jupyter_output><empty_output><jupyter_text>Expected result:![An isosceles triangle in the y=0 plane](assets/02_one_triangle.png "The simplest mesh: a single triangle")The arguments we passed to the `mesh()` function are a vertex array (a `list` or NumPy's `ndarray` is OK) which is composed of $(x, y, z)$ coordinates and an array of index triplets (`int`s). Each triplet refers to the vertex array, defining one triangle.We can of course add objects directly to the plot, without creating variables:<jupyter_code>plot += k3d.mesh([0, 1, 1, 
                 1, 1, 0, 
                 1, 1, 1,
                 
                 1, 1, 1,
                 1, 2, 2,
                 2, 1, 1], [0, 1, 2, 3, 4, 5], color=0x00ff00)

plot<jupyter_output><empty_output><jupyter_text>Expected result:![One blue and two green triangles](assets/02_two_triangles.png "Three triangles, two Mesh objects")This is a plot of two meshes. Please note -- in the second case we didn't nest the triplets - the numbers run continuously in a flat list. We also used an optional argument, `color` to specify the color of the second object. K3D objects have many attributes, which we can find out about from the docstrings and from other examples, dedicated to the specific object type.Back to the main topic. The `plot` keeps track of the objects that it contains:<jupyter_code>len(plot.objects)<jupyter_output><empty_output><jupyter_text>We have 2 displays of the plot in the notebook, associated with 2 different cell outputs.However, they are the same plot - you should see the same scene (3 triangles) on both of them.Each view of the plot can be adjusted separately using the mouse.When the plot becomes too cluttered with objects, we may want to remove some of them.This is easily done with the `-=` operator. This is the place, where having named our objects beforehand comes in handy:<jupyter_code>plot -= mesh
plot<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08746355685131195, 'fraction_numerical': 0.023740108288213244, 'mean_word_length': 3.9628099173553717, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '340010', 'license': 'MIT', 'n_tokens_mistral': 755, 'n_tokens_neox': 695, 'n_words': 332, 'path': 'examples/02_adding_objects_to_plot.ipynb', 'repo_name': 'annefou/K3D-jupyter', 'size': '2401'}