Skip to content

Commit 674a478

Browse files
committed
add readme.md
bump version
1 parent cb901dd commit 674a478

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# plotly_3d_primitives
2+
3+
A small library for quickly generating 3d traces (`Mesh3d` and `Scatter3d`) of primitive shapes.
4+
5+
The API is intentionally designed to mimic PyVista so that, for the supported geometries, it could be a drop-in replacement.
6+
7+
## Primitives currently supported
8+
9+
- `cube`
10+
- `sphere`
11+
- `prism` (with n-sides)
12+
- `cone`
13+
- `line`
14+
- `circular_arc_from_normal`
15+
16+
## Installation and basic usage
17+
18+
```
19+
pip install plotly_3d_primitives
20+
```
21+
22+
Each primitive is created from a function which returns a `plotly.graph_objects.Trace`, generally either a `plotly.graph_objects.Mesh3d` or a `plotly.graph_objects.Scatter3d`.
23+
24+
```python
25+
import plotly_3d_primitives as prims
26+
import plotly.graph_objects as go
27+
28+
a_cube = prims.cube(x_length=30, y_length=24, z_length=18, color='teal', opacity=0.5)
29+
30+
a_sphere = prims.sphere(radius=6.8, center=(-3, 0, 20), color="papayawhip", opacity=0.8) # everyone's favourite colour
31+
32+
a_cylinder = prims.prism(radius=10, center=(4, 10, 14), height=12, color="goldenrod", n_sides=12)
33+
34+
an_arc = prims.circular_arc_from_normal(center= (20, 10, 10), normal=(0, 1, 0), angle=215, color='red', line_width=10)
35+
36+
a_cone = prims.cone(center=(-5, -10, -6), direction=(0, 0, 1), height=14, radius=4, color='green', opacity=0.2)
37+
38+
a_line = prims.line(pointa=(1, -5, -10), pointb=(14, 23, 10), color="#333", opacity=1.0, line_width=15)
39+
40+
fig = go.Figure()
41+
layout = go.Layout(scene=dict(aspectmode='data'), width=800, height=800)
42+
fig.layout = layout
43+
44+
fig.add_traces([a_cube, a_sphere, a_cylinder, an_arc, a_cone, a_line])
45+
fig.show()
46+
```
47+
48+
## Motivation
49+
50+
Getting easy-and-consistent 3d geometry display in Python for the web can be fussy. VTK and PyVista are great buuuuuttt...PyVista (currently) does not work with streamlit. PyVista also requires a LOT of dependencies to be installed in order to work in a Jupyter environment.
51+
52+
Plotly is easy to install and displays in any web environment. It has great built-in display features (hover, annotations, click-button screenshots) and an easy-to-understand data model.
53+
54+
So, I have implemented **some** of PyVista's functionality in Plotly so it can be used as a drop-in replacement for these primitives.
55+
56+
**Contributions for other primitives and additional PyVista functionality is welcome.**
57+
58+
The functionality currently implemented is enough for me to create an alternative visualization module for the structural analysis library, [PyNite](https://github.com/jwock82/pynite). This was the primary motivation for creating this library but I have also used it in other locations.
59+
60+
**Note:** Plotly is not designed to handle large amounts of detailed 3d meshes. If you use this library to build large models, you can stall-out plotly and hang your browser. So, try to keep it light.

src/plotly_3d_primitives/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
shapes in plotly
44
"""
55

6-
__version__ = "0.1.0"
6+
__version__ = "0.2.0"
77

88
from .shapes import *

0 commit comments

Comments
 (0)