Skip to content

Commit b8e2967

Browse files
authored
Merge pull request #1031 from compas-dev/plotter-fix-add-from-list
Remove duplicate value of param
2 parents 5d54011 + 70b7d68 commit b8e2967

File tree

2 files changed

+70
-58
lines changed

2 files changed

+70
-58
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424

2525
* Set `jinja >= 3.0` to dev dependencies to fix docs build error.
2626
* Fixed removing of collections for `compas_plotters`.
27+
* Fixed bug in `compas_plotters.plotter.Plotter.add_from_list`.
2728
* Fixed bug in `compas.robots.Configuration`.
2829
* Rebuild part index after deserialization in `Assembly`.
2930
* Fixed bug in `compas.artists.colordict.ColorDict`.

src/compas_plotters/plotter.py

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,18 @@ class Plotter:
104104

105105
fontsize = 12
106106

107-
def __init__(self,
108-
view: Tuple[Tuple[float, float], Tuple[float, float]] = ((-8.0, 16.0), (-5.0, 10.0)),
109-
figsize: Tuple[float, float] = (8.0, 5.0),
110-
dpi: float = 100,
111-
bgcolor: Tuple[float, float, float] = (1.0, 1.0, 1.0),
112-
show_axes: bool = False,
113-
zstack: Literal['natural', 'zorder'] = 'zorder'):
107+
def __init__(
108+
self,
109+
view: Tuple[Tuple[float, float], Tuple[float, float]] = (
110+
(-8.0, 16.0),
111+
(-5.0, 10.0),
112+
),
113+
figsize: Tuple[float, float] = (8.0, 5.0),
114+
dpi: float = 100,
115+
bgcolor: Tuple[float, float, float] = (1.0, 1.0, 1.0),
116+
show_axes: bool = False,
117+
zstack: Literal["natural", "zorder"] = "zorder",
118+
):
114119
self._show_axes = show_axes
115120
self._bgcolor = None
116121
self._viewbox = None
@@ -136,28 +141,28 @@ def viewbox(self, view: Tuple[Tuple[float, float], Tuple[float, float]]):
136141
@property
137142
def axes(self) -> matplotlib.axes.Axes:
138143
if not self._axes:
139-
figure = plt.figure(facecolor=self.bgcolor,
140-
figsize=self.figsize,
141-
dpi=self.dpi)
142-
axes = figure.add_subplot(111, aspect='equal')
144+
figure = plt.figure(
145+
facecolor=self.bgcolor, figsize=self.figsize, dpi=self.dpi
146+
)
147+
axes = figure.add_subplot(111, aspect="equal")
143148
if self.viewbox:
144149
xmin, xmax = self.viewbox[0]
145150
ymin, ymax = self.viewbox[1]
146151
axes.set_xlim(xmin, xmax)
147152
axes.set_ylim(ymin, ymax)
148-
axes.set_xscale('linear')
149-
axes.set_yscale('linear')
153+
axes.set_xscale("linear")
154+
axes.set_yscale("linear")
150155
if self._show_axes:
151156
axes.set_frame_on(True)
152157
axes.grid(False)
153158
axes.set_xticks([])
154159
axes.set_yticks([])
155-
axes.spines['top'].set_color('none')
156-
axes.spines['right'].set_color('none')
157-
axes.spines['left'].set_position('zero')
158-
axes.spines['bottom'].set_position('zero')
159-
axes.spines['left'].set_linestyle('-')
160-
axes.spines['bottom'].set_linestyle('-')
160+
axes.spines["top"].set_color("none")
161+
axes.spines["right"].set_color("none")
162+
axes.spines["left"].set_position("zero")
163+
axes.spines["bottom"].set_position("zero")
164+
axes.spines["left"].set_linestyle("-")
165+
axes.spines["bottom"].set_linestyle("-")
161166
else:
162167
axes.grid(False)
163168
axes.set_frame_on(False)
@@ -220,7 +225,7 @@ def zoom_extents(self, padding: Optional[int] = None) -> None:
220225
data = []
221226
for artist in self.artists:
222227
data += artist.data
223-
x, y = zip(* data)
228+
x, y = zip(*data)
224229
xmin = min(x)
225230
xmax = max(x)
226231
ymin = min(y)
@@ -243,12 +248,16 @@ def zoom_extents(self, padding: Optional[int] = None) -> None:
243248
self.axes.set_ylim(*ylim)
244249
self.axes.autoscale_view()
245250

246-
def add(self,
247-
item: Union[compas.geometry.Primitive,
248-
compas.datastructures.Network,
249-
compas.datastructures.Mesh],
250-
artist: Optional[PlotterArtist] = None,
251-
**kwargs) -> PlotterArtist:
251+
def add(
252+
self,
253+
item: Union[
254+
compas.geometry.Primitive,
255+
compas.datastructures.Network,
256+
compas.datastructures.Mesh,
257+
],
258+
artist: Optional[PlotterArtist] = None,
259+
**kwargs,
260+
) -> PlotterArtist:
252261
"""Add a COMPAS geometry object or data structure to the plot.
253262
254263
Parameters
@@ -264,39 +273,33 @@ def add(self,
264273
265274
"""
266275
if not artist:
267-
if self.zstack == 'natural':
276+
if self.zstack == "natural":
268277
zorder = 1000 + len(self._artists) * 100
269-
artist = PlotterArtist(item, plotter=self, zorder=zorder, context='Plotter', **kwargs)
278+
artist = PlotterArtist(
279+
item, plotter=self, zorder=zorder, context="Plotter", **kwargs
280+
)
270281
else:
271-
artist = PlotterArtist(item, plotter=self, context='Plotter', **kwargs)
282+
artist = PlotterArtist(item, plotter=self, context="Plotter", **kwargs)
272283
artist.draw()
273284
self._artists.append(artist)
274285
return artist
275286

276-
# def add_as(self,
277-
# item: Union[compas.geometry.Primitive,
278-
# compas.datastructures.Network,
279-
# compas.datastructures.Mesh],
280-
# artist_type: PlotterArtist,
281-
# **kwargs) -> PlotterArtist:
282-
# """Add a COMPAS geometry object or data structure using a specific artist type."""
283-
# artist = PlotterArtist(item, artist_type=artist_type, context='Plotter', **kwargs)
284-
# artist.draw()
285-
# self._artists.append(artist)
286-
# return artist
287-
288287
def add_from_list(self, items, **kwargs) -> List[PlotterArtist]:
289288
"""Add multiple COMPAS geometry objects and/or data structures from a list."""
290289
artists = []
291290
for item in items:
292-
artist = self.add(item, plotter=self, **kwargs)
291+
artist = self.add(item, **kwargs)
293292
artists.append(artist)
294293
return artists
295294

296-
def find(self,
297-
item: Union[compas.geometry.Primitive,
298-
compas.datastructures.Network,
299-
compas.datastructures.Mesh]) -> PlotterArtist:
295+
def find(
296+
self,
297+
item: Union[
298+
compas.geometry.Primitive,
299+
compas.datastructures.Network,
300+
compas.datastructures.Mesh,
301+
],
302+
) -> PlotterArtist:
300303
"""Find a geometry object or data structure in the plot."""
301304
for artist in self._artists:
302305
if item is artist.item:
@@ -325,7 +328,7 @@ def register_listener(self, listener: Callable) -> None:
325328
.. [2] https://matplotlib.org/users/event_handling.html
326329
327330
"""
328-
self.figure.canvas.mpl_connect('pick_event', listener)
331+
self.figure.canvas.mpl_connect("pick_event", listener)
329332

330333
def draw(self, pause: Optional[float] = None) -> None:
331334
"""Draw all objects included in the plot."""
@@ -351,8 +354,7 @@ def redraw(self, pause: Optional[float] = None) -> None:
351354
plt.pause(pause)
352355

353356
def show(self) -> None:
354-
"""Displays the plot.
355-
"""
357+
"""Displays the plot."""
356358
self.draw()
357359
plt.show()
358360

@@ -375,16 +377,18 @@ def save(self, filepath: str, **kwargs) -> None:
375377
"""
376378
plt.savefig(filepath, **kwargs)
377379

378-
def on(self,
379-
interval: int = None,
380-
frames: int = None,
381-
record: bool = False,
382-
recording: str = None,
383-
dpi: int = 150) -> Callable:
380+
def on(
381+
self,
382+
interval: int = None,
383+
frames: int = None,
384+
record: bool = False,
385+
recording: str = None,
386+
dpi: int = 150,
387+
) -> Callable:
384388
"""Method for decorating callback functions in dynamic plots."""
385389
if record:
386390
if not recording:
387-
raise Exception('Please provide a path for the recording.')
391+
raise Exception("Please provide a path for the recording.")
388392

389393
def outer(func: Callable):
390394
if record:
@@ -394,13 +398,20 @@ def outer(func: Callable):
394398
func(f)
395399
self.redraw(pause=interval)
396400
if record:
397-
filepath = os.path.join(dirpath, f'frame-{f}.png')
401+
filepath = os.path.join(dirpath, f"frame-{f}.png")
398402
paths.append(filepath)
399403
self.save(filepath, dpi=dpi)
400404
images = []
401405
for path in paths:
402406
images.append(Image.open(path))
403-
images[0].save(recording, save_all=True, append_images=images[1:], optimize=False, duration=interval * 1000, loop=0)
407+
images[0].save(
408+
recording,
409+
save_all=True,
410+
append_images=images[1:],
411+
optimize=False,
412+
duration=interval * 1000,
413+
loop=0,
414+
)
404415
else:
405416
for f in range(frames):
406417
func(f)

0 commit comments

Comments
 (0)