Skip to content

Commit 8565780

Browse files
committed
more tutorial
1 parent 5e41daf commit 8565780

File tree

10 files changed

+221
-18
lines changed

10 files changed

+221
-18
lines changed
127 KB
Loading
30.4 KB
Loading
109 KB
Loading
61.9 KB
Loading

docs/tutorial/plotters.rst

Lines changed: 152 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,34 +129,169 @@ Also in this case, the ``z`` coordinates of the geometry is ignored, and only a
129129
Visualisation Options
130130
=====================
131131

132-
All line objects (line, polyline) have the following options
132+
Line and Polyline
133+
-----------------
134+
135+
.. rst-class:: table table-bordered
136+
137+
.. list-table::
138+
:widths: auto
139+
:header-rows: 1
140+
141+
* - Name
142+
- Value
143+
- Default
144+
* - ``linewidth``
145+
- :obj:`float`
146+
- ``1.0``
147+
* - ``linestyle``
148+
- ``{'solid', 'dotted', 'dashed', 'dashdot'}``
149+
- ``'solid'``
150+
* - ``color``
151+
- :obj:`tuple`
152+
- ``(0.0, 0.0, 0.0)``
153+
* - ``draw_points``
154+
- :obj:`bool`
155+
- ``False``
133156

134-
* ``linewidth``: a positive number with as default ``1.0``
135-
* ``linestyle``: one of ``{'solid', 'dotted', 'dashed', 'dashdot'}`` with as default ``'solid'``
136-
* ``color``: an rgb color tuple with components in the range of ``0.0`` to ``1.0``, and as default ``(0.0, 0.0, 0.0)``
137-
* ``draw_points``: a boolean flag indicating that the underlying points should also be draw; the default is ``False``
157+
.. code-block:: python
158+
159+
pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)
160+
161+
for a, b in grouper(pointcloud, 2):
162+
line = Line(a, b)
163+
plotter.add(line,
164+
linewidth=2.0,
165+
linestyle=random.choice(['dotted', 'dashed', 'solid']),
166+
color=i_to_rgb(random.random(), normalize=True),
167+
draw_points=True)
168+
169+
.. figure:: /_images/tutorial/plotters_line-options.png
170+
:figclass: figure
171+
:class: figure-img img-fluid
172+
173+
174+
Circle, Ellipse, Polygon
175+
------------------------
176+
177+
.. rst-class:: table table-bordered
178+
179+
.. list-table::
180+
:widths: auto
181+
:header-rows: 1
182+
183+
* - Name
184+
- Value
185+
- Default
186+
* - ``linewidth``
187+
- :obj:`float`
188+
- ``1.0``
189+
* - ``linestyle``
190+
- ``{'solid', 'dotted', 'dashed', 'dashdot'}``
191+
- ``'solid'``
192+
* - ``facecolor``
193+
- :obj:`tuple`
194+
- ``(1.0, 1.0, 1.0)``
195+
* - ``edgecolor``
196+
- :obj:`tuple`
197+
- ``(0.0, 0.0, 0.0)``
198+
* - ``alpha``
199+
- :obj:`float`
200+
- ``1.0``
201+
* - ``fill``
202+
- :obj:`bool`
203+
- ``True``
204+
205+
.. code-block:: python
206+
207+
poly1 = Polygon.from_sides_and_radius_xy(5, 1.0)
208+
poly2 = Polygon.from_sides_and_radius_xy(5, 1.0).transformed(Translation.from_vector([0.5, -0.25, 0]))
209+
poly3 = Polygon.from_sides_and_radius_xy(5, 1.0).transformed(Translation.from_vector([0.75, +0.25, 0]))
210+
211+
plotter.add(poly1, linewidth=3.0, facecolor=(0.8, 1.0, 0.8), edgecolor=(0.0, 1.0, 0.0))
212+
plotter.add(poly2, linestyle='dashed', facecolor=(1.0, 0.8, 0.8), edgecolor=(1.0, 0.0, 0.0))
213+
plotter.add(poly3, alpha=0.5)
214+
215+
.. figure:: /_images/tutorial/plotters_polygon-options.png
216+
:figclass: figure
217+
:class: figure-img img-fluid
218+
219+
220+
Points
221+
------
138222

139-
All objects with an interior region (circle, ellipse, polygon) have
223+
.. rst-class:: table table-bordered
140224

141-
* ``linewidth``: a positive number with as default ``1.0``
142-
* ``linestyle``: one of ``{'solid', 'dotted', 'dashed', 'dashdot'}`` with as default ``'solid'``
143-
* ``facecolor``: an rgb color tuple with components in the range of ``0.0`` to ``1.0``, and as default ``(1.0, 1.0, 1.0)``, specifying the color of the interior region
144-
* ``edgecolor``: an rgb color tuple with components in the range of ``0.0`` to ``1.0``, and as default ``(0.0, 0.0, 0.0)``, specifying the color of the boundary
145-
* ``fill``: a boolean flag indicating that the interior should be filled; the default is ``True``.
146-
* ``alpha``: controls the transparency of the fill in a range of ``0.0`` to ``1.0``, with as default ``1.0``
225+
.. list-table::
226+
:widths: auto
227+
:header-rows: 1
147228

148-
Point objects have their own set of options
229+
* - Name
230+
- Value
231+
- Default
232+
* - ``size``
233+
- :obj:`int`
234+
- ``5``
235+
* - ``facecolor``
236+
- :obj:`tuple`
237+
- ``(1.0, 1.0, 1.0)``
238+
* - ``edgecolor``
239+
- :obj:`tuple`
240+
- ``(0.0, 0.0, 0.0)``
149241

150-
* ``size``
151-
* ``facecolor``: an rgb color tuple with components in the range of ``0.0`` to ``1.0``, and as default ``(1.0, 1.0, 1.0)``, specifying the color of the interior region
152-
* ``edgecolor``: an rgb color tuple with components in the range of ``0.0`` to ``1.0``, and as default ``(0.0, 0.0, 0.0)``, specifying the color of the boundary
242+
.. code-block:: python
243+
244+
pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)
245+
246+
for point in pointcloud:
247+
plotter.add(point, size=random.randint(1, 10), edgecolor=i_to_rgb(random.random(), normalize=True))
248+
249+
.. figure:: /_images/tutorial/plotters_point-options.png
250+
:figclass: figure
251+
:class: figure-img img-fluid
252+
253+
254+
Vectors
255+
-------
256+
257+
.. rst-class:: table table-bordered
153258

154-
Note that since point objects are visualised as circles in ...
259+
.. list-table::
260+
:widths: auto
261+
:header-rows: 1
262+
263+
* - Name
264+
- Value
265+
- Default
266+
* - ``point``
267+
- :class:`compas.geometry.Point`
268+
- ``None``
269+
* - ``draw_point``
270+
- :obj:`bool`
271+
- ``False``
272+
* - ``color``
273+
- :obj:`tuple`
274+
- ``(0.0, 0.0, 0.0)``
275+
276+
.. code-block:: python
277+
278+
pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)
279+
280+
for index, (a, b) in enumerate(pairwise(pointcloud)):
281+
vector = b - a
282+
vector.unitize()
283+
plotter.add(vector, point=a, draw_point=True, color=i_to_red(max(index / 10, 0.1), normalize=True))
284+
285+
.. figure:: /_images/tutorial/plotters_vector-options.png
286+
:figclass: figure
287+
:class: figure-img img-fluid
155288

156289

157290
Dynamic Plots
158291
=============
159292

293+
Interactive Plots
294+
=================
160295

161296
Exports
162297
=======
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import random
2+
from compas.geometry import Line
3+
from compas.geometry import Pointcloud
4+
from compas.utilities import i_to_rgb, grouper
5+
6+
from compas_plotters import Plotter
7+
8+
pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)
9+
10+
11+
plotter = Plotter(figsize=(8, 5))
12+
13+
for a, b in grouper(pointcloud, 2):
14+
if a and b:
15+
line = Line(a, b)
16+
plotter.add(line,
17+
linewidth=2.0,
18+
linestyle=random.choice(['dotted', 'dashed', 'solid']),
19+
color=i_to_rgb(random.random(), normalize=True),
20+
draw_points=True)
21+
22+
plotter.zoom_extents()
23+
plotter.save('docs/_images/tutorial/plotters_line-options.png', dpi=300)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import random
2+
from compas.geometry import Pointcloud
3+
from compas.utilities import i_to_rgb
4+
5+
from compas_plotters import Plotter
6+
7+
pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)
8+
9+
plotter = Plotter(figsize=(8, 5))
10+
for point in pointcloud:
11+
plotter.add(point, size=random.randint(1, 10), edgecolor=i_to_rgb(random.random(), normalize=True))
12+
plotter.zoom_extents()
13+
plotter.save('docs/_images/tutorial/plotters_point-options.png', dpi=300)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from compas.geometry import Polygon, Translation
2+
3+
from compas_plotters import Plotter
4+
5+
poly1 = Polygon.from_sides_and_radius_xy(5, 1.0)
6+
poly2 = Polygon.from_sides_and_radius_xy(5, 1.0).transformed(Translation.from_vector([0.5, -0.25, 0]))
7+
poly3 = Polygon.from_sides_and_radius_xy(5, 1.0).transformed(Translation.from_vector([0.75, +0.25, 0]))
8+
9+
plotter = Plotter(figsize=(8, 5))
10+
plotter.add(poly1, linewidth=3.0, facecolor=(0.8, 1.0, 0.8), edgecolor=(0.0, 1.0, 0.0))
11+
plotter.add(poly2, linestyle='dashed', facecolor=(1.0, 0.8, 0.8), edgecolor=(1.0, 0.0, 0.0))
12+
plotter.add(poly3, alpha=0.5)
13+
plotter.zoom_extents()
14+
plotter.save('docs/_images/tutorial/plotters_polygon-options.png', dpi=300)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from compas.geometry import Pointcloud
2+
from compas.utilities import i_to_red, pairwise
3+
4+
from compas_plotters import Plotter
5+
6+
plotter = Plotter(figsize=(8, 5))
7+
8+
pointcloud = Pointcloud.from_bounds(8, 5, 0, 10)
9+
10+
for index, (a, b) in enumerate(pairwise(pointcloud)):
11+
vector = b - a
12+
vector.unitize()
13+
plotter.add(vector, point=a, draw_point=True, color=i_to_red(max(index / 10, 0.1), normalize=True))
14+
15+
plotter.add(b, size=10, edgecolor=(1, 0, 0))
16+
17+
plotter.zoom_extents()
18+
plotter.save('docs/_images/tutorial/plotters_vector-options.png', dpi=300)

src/compas_plotters/artists/polygonartist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def data(self) -> List[List[float]]:
3636
def draw(self) -> None:
3737
polygon = PolygonPatch(self.data,
3838
linewidth=self.linewidth,
39-
linestyle='solid',
39+
linestyle=self.linestyle,
4040
facecolor=self.facecolor,
4141
edgecolor=self.edgecolor,
4242
zorder=self.zorder,

0 commit comments

Comments
 (0)