1
1
from __future__ import absolute_import
2
- import warnings
3
2
import time
4
3
import math
5
4
8
7
from pyaedt .modeler .GeometryOperators import GeometryOperators
9
8
from pyaedt .generic .constants import CSS4_COLORS
10
9
from pyaedt .edb_core .EDB_Data import EDBNetsData
11
-
12
- if not is_ironpython :
13
- try :
14
- from matplotlib import pyplot as plt
15
- from matplotlib .path import Path
16
- from matplotlib .patches import PathPatch
17
- except ImportError :
18
- mess = "The Matplotlib module is required to run some functionalities.\n "
19
- mess += "Install with \n pip install matplotlib"
20
- warnings .warn (mess )
21
- except :
22
- pass
10
+ from pyaedt .generic .plot import plot_matplotlib
23
11
24
12
25
13
class EdbNets (object ):
@@ -221,10 +209,14 @@ def _get_points_for_plot(self, my_net_points):
221
209
return x , y
222
210
223
211
@aedt_exception_handler
224
- def plot (
225
- self , nets , layers = None , color_by_net = False , show_legend = True , save_plot = None , outline = None , size = (2000 , 1000 )
212
+ def get_plot_data (
213
+ self ,
214
+ nets ,
215
+ layers = None ,
216
+ color_by_net = False ,
217
+ outline = None ,
226
218
):
227
- """Plot a Net to Matplotlib 2D Chart.
219
+ """Return List of points for Matplotlib 2D Chart.
228
220
229
221
Parameters
230
222
----------
@@ -235,35 +227,21 @@ def plot(
235
227
color_by_net : bool, optional
236
228
If `True` the plot will be colored by net.
237
229
If `False` the plot will be colored by layer. (default)
238
- show_legend : bool, optional
239
- If `True` the legend is shown in the plot. (default)
240
- If `False` the legend is not shown.
241
- save_plot : str, optional
242
- If `None` the plot will be shown.
243
- If a file path is specified the plot will be saved to such file.
244
230
outline : list, optional
245
231
List of points of the outline to plot.
246
- size : tuple, optional
247
- Image size in pixel (width, height).
248
232
"""
249
233
start_time = time .time ()
250
- if is_ironpython :
251
- self ._logger .warning ("Plot functionalities are enabled only in CPython." )
252
- return False
234
+ color_index = 0
253
235
if not layers :
254
236
layers = list (self ._pedb .core_stackup .signal_layers .keys ())
255
237
if not nets :
256
238
nets = list (self .nets .keys ())
239
+ objects_lists = []
257
240
label_colors = {}
258
- color_index = 0
259
- dpi = 100.0
260
- figsize = (size [0 ] / dpi , size [1 ] / dpi )
261
- fig , ax = plt .subplots (figsize = figsize )
262
241
if outline :
263
242
x1 = [i [0 ] for i in outline ]
264
243
y1 = [i [1 ] for i in outline ]
265
- plt .fill (x1 , y1 , c = "b" , label = "Outline" , alpha = 0.3 )
266
-
244
+ objects_lists .append ([x1 , y1 , "b" , "Outline" , 0.3 , "fill" ])
267
245
if isinstance (nets , str ):
268
246
nets = [nets ]
269
247
@@ -279,26 +257,27 @@ def plot(
279
257
if label not in label_colors :
280
258
color = path .layer .GetColor ()
281
259
try :
282
- c = (color .Item1 / 255 , color .Item2 / 255 , color .Item3 / 255 )
260
+ c = (float ( color .Item1 / 255 ), float ( color .Item2 / 255 ), float ( color .Item3 / 255 ) )
283
261
label_colors [label ] = c
284
262
except :
285
263
label_colors [label ] = list (CSS4_COLORS .keys ())[color_index ]
286
264
color_index += 1
287
265
if color_index >= len (CSS4_COLORS ):
288
266
color_index = 0
289
- plt . fill ( x , y , c = label_colors [label ], label = label , alpha = 0.4 )
267
+ objects_lists . append ([ x , y , label_colors [label ], label , 0.4 , "fill" ] )
290
268
else :
291
- plt .fill (x , y , c = label_colors [label ], alpha = 0.4 )
269
+ objects_lists .append ([x , y , label_colors [label ], None , 0.4 , "fill" ])
270
+
292
271
else :
293
272
label = "Net " + net_name
294
273
if label not in label_colors :
295
274
label_colors [label ] = list (CSS4_COLORS .keys ())[color_index ]
296
275
color_index += 1
297
276
if color_index >= len (CSS4_COLORS ):
298
277
color_index = 0
299
- plt . fill ( x , y , c = label_colors [label ], label = label , alpha = 0.4 )
278
+ objects_lists . append ([ x , y , label_colors [label ], label , 0.4 , "fill" ] )
300
279
else :
301
- plt . fill ( x , y , c = label_colors [label ], alpha = 0.4 )
280
+ objects_lists . append ([ x , y , label_colors [label ], None , 0.4 , "fill" ] )
302
281
303
282
for poly in self ._pedb .core_primitives .polygons :
304
283
if poly .is_void :
@@ -311,43 +290,42 @@ def plot(
311
290
continue
312
291
x , y = GeometryOperators .orient_polygon (xt , yt , clockwise = True )
313
292
vertices = [(i , j ) for i , j in zip (x , y )]
314
- codes = [Path . LINETO for _ in vertices ]
315
- codes [0 ] = Path . MOVETO
293
+ codes = [2 for _ in vertices ]
294
+ codes [0 ] = 1
316
295
vertices .append ((0 , 0 ))
317
- codes .append (Path . CLOSEPOLY )
296
+ codes .append (79 )
318
297
319
298
for void in poly .voids :
320
299
xvt , yvt = void .points ()
321
300
if xvt :
322
301
xv , yv = GeometryOperators .orient_polygon (xvt , yvt , clockwise = False )
323
302
tmpV = [(i , j ) for i , j in zip (xv , yv )]
324
303
vertices .extend (tmpV )
325
- tmpC = [Path . LINETO for _ in tmpV ]
326
- tmpC [0 ] = Path . MOVETO
304
+ tmpC = [2 for _ in tmpV ]
305
+ tmpC [0 ] = 1
327
306
codes .extend (tmpC )
328
307
vertices .append ((0 , 0 ))
329
- codes .append (Path .CLOSEPOLY )
330
-
331
- # create Path object from vertices and codes
332
- path = Path (vertices , codes )
308
+ codes .append (79 )
333
309
334
310
if not color_by_net :
335
311
label = "Layer " + layer_name
336
312
if label not in label_colors :
337
313
color = poly .GetLayer ().GetColor ()
338
314
try :
339
- c = (color .Item1 / 255 , color .Item2 / 255 , color .Item3 / 255 )
315
+ c = (float ( color .Item1 / 255 ), float ( color .Item2 / 255 ), float ( color .Item3 / 255 ) )
340
316
label_colors [label ] = c
341
317
except :
342
318
label_colors [label ] = list (CSS4_COLORS .keys ())[color_index ]
343
319
color_index += 1
344
320
if color_index >= len (CSS4_COLORS ):
345
321
color_index = 0
346
322
# create patch from path
347
- patch = PathPatch (path , color = label_colors [label ], alpha = 0.4 , label = label )
323
+ objects_lists .append ([vertices , codes , label_colors [label ], label , 0.4 , "path" ])
324
+
348
325
else :
349
326
# create patch from path
350
- patch = PathPatch (path , color = label_colors [label ], alpha = 0.4 )
327
+ objects_lists .append ([vertices , codes , label_colors [label ], "" , 0.4 , "path" ])
328
+
351
329
else :
352
330
label = "Net " + net_name
353
331
if label not in label_colors :
@@ -356,24 +334,50 @@ def plot(
356
334
if color_index >= len (CSS4_COLORS ):
357
335
color_index = 0
358
336
# create patch from path
359
- patch = PathPatch ( path , color = label_colors [label ], alpha = 0.4 , label = label )
337
+ objects_lists . append ([ vertices , codes , label_colors [label ], label , 0.4 , "path" ] )
360
338
else :
361
339
# create patch from path
362
- patch = PathPatch (path , color = label_colors [label ], alpha = 0.4 )
340
+ objects_lists .append ([vertices , codes , label_colors [label ], "" , 0.4 , "path" ])
341
+ end_time = time .time () - start_time
342
+ self ._logger .info ("Nets Point Generation time %s seconds" , round (end_time , 3 ))
343
+ return objects_lists
363
344
364
- # plot the patch
365
- ax .add_patch (patch )
345
+ @aedt_exception_handler
346
+ def plot (
347
+ self , nets , layers = None , color_by_net = False , show_legend = True , save_plot = None , outline = None , size = (2000 , 1000 )
348
+ ):
349
+ """Plot a Net to Matplotlib 2D Chart.
366
350
367
- ax .set (xlabel = "X (m)" , ylabel = "Y (m)" , title = self ._pedb .active_cell .GetName ())
368
- if show_legend :
369
- ax .legend ()
370
- ax .axis ("equal" )
371
- end_time = time .time () - start_time
372
- self ._logger .info ("Plot Generation time %s seconds" , round (end_time , 3 ))
373
- if save_plot :
374
- plt .savefig (save_plot )
375
- else :
376
- plt .show ()
351
+ Parameters
352
+ ----------
353
+ nets : str, list
354
+ Name of the net or list of nets to plot. If `None` all nets will be plotted.
355
+ layers : str, list, optional
356
+ Name of the layers to include in the plot. If `None` all the signal layers will be considered.
357
+ color_by_net : bool, optional
358
+ If `True` the plot will be colored by net.
359
+ If `False` the plot will be colored by layer. (default)
360
+ show_legend : bool, optional
361
+ If `True` the legend is shown in the plot. (default)
362
+ If `False` the legend is not shown.
363
+ save_plot : str, optional
364
+ If `None` the plot will be shown.
365
+ If a file path is specified the plot will be saved to such file.
366
+ outline : list, optional
367
+ List of points of the outline to plot.
368
+ size : tuple, optional
369
+ Image size in pixel (width, height). Default value is ``(2000, 1000)``
370
+ """
371
+ if is_ironpython :
372
+ self ._logger .warning ("Plot functionalities are enabled only in CPython." )
373
+ return False
374
+ object_lists = self .get_plot_data (
375
+ nets ,
376
+ layers ,
377
+ color_by_net ,
378
+ outline ,
379
+ )
380
+ plot_matplotlib (object_lists , size , show_legend , "X (m)" , "Y (m)" , self ._pedb .active_cell .GetName (), save_plot )
377
381
378
382
@aedt_exception_handler
379
383
def is_power_gound_net (self , netname_list ):
0 commit comments