topologicpy 0.4.8__py3-none-any.whl → 0.4.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. topologicpy/Aperture.py +46 -0
  2. topologicpy/Cell.py +1780 -0
  3. topologicpy/CellComplex.py +791 -0
  4. topologicpy/Cluster.py +591 -0
  5. topologicpy/Color.py +157 -0
  6. topologicpy/Context.py +56 -0
  7. topologicpy/DGL.py +2661 -0
  8. topologicpy/Dictionary.py +470 -0
  9. topologicpy/Edge.py +855 -0
  10. topologicpy/EnergyModel.py +1052 -0
  11. topologicpy/Face.py +1810 -0
  12. topologicpy/Graph.py +3526 -0
  13. topologicpy/Graph_Export.py +858 -0
  14. topologicpy/Grid.py +338 -0
  15. topologicpy/Helper.py +182 -0
  16. topologicpy/Honeybee.py +424 -0
  17. topologicpy/Matrix.py +255 -0
  18. topologicpy/Neo4jGraph.py +311 -0
  19. topologicpy/Plotly.py +1396 -0
  20. topologicpy/Polyskel.py +524 -0
  21. topologicpy/Process.py +1368 -0
  22. topologicpy/SQL.py +48 -0
  23. topologicpy/Shell.py +1418 -0
  24. topologicpy/Speckle.py +433 -0
  25. topologicpy/Topology.py +5854 -0
  26. topologicpy/UnitTest.py +29 -0
  27. topologicpy/Vector.py +555 -0
  28. topologicpy/Vertex.py +714 -0
  29. topologicpy/Wire.py +2346 -0
  30. topologicpy/__init__.py +20 -0
  31. topologicpy/bin/linux/topologic/__init__.py +2 -0
  32. topologicpy/bin/linux/topologic/topologic.cpython-310-x86_64-linux-gnu.so +0 -0
  33. topologicpy/bin/linux/topologic/topologic.cpython-311-x86_64-linux-gnu.so +0 -0
  34. topologicpy/bin/linux/topologic/topologic.cpython-38-x86_64-linux-gnu.so +0 -0
  35. topologicpy/bin/linux/topologic/topologic.cpython-39-x86_64-linux-gnu.so +0 -0
  36. topologicpy/bin/linux/topologic.libs/libTKBO-6bdf205d.so.7.7.0 +0 -0
  37. topologicpy/bin/linux/topologic.libs/libTKBRep-2960a069.so.7.7.0 +0 -0
  38. topologicpy/bin/linux/topologic.libs/libTKBool-c44b74bd.so.7.7.0 +0 -0
  39. topologicpy/bin/linux/topologic.libs/libTKFillet-9a670ba0.so.7.7.0 +0 -0
  40. topologicpy/bin/linux/topologic.libs/libTKG2d-8f31849e.so.7.7.0 +0 -0
  41. topologicpy/bin/linux/topologic.libs/libTKG3d-4c6bce57.so.7.7.0 +0 -0
  42. topologicpy/bin/linux/topologic.libs/libTKGeomAlgo-26066fd9.so.7.7.0 +0 -0
  43. topologicpy/bin/linux/topologic.libs/libTKGeomBase-2116cabe.so.7.7.0 +0 -0
  44. topologicpy/bin/linux/topologic.libs/libTKMath-72572fa8.so.7.7.0 +0 -0
  45. topologicpy/bin/linux/topologic.libs/libTKMesh-2a060427.so.7.7.0 +0 -0
  46. topologicpy/bin/linux/topologic.libs/libTKOffset-6cab68ff.so.7.7.0 +0 -0
  47. topologicpy/bin/linux/topologic.libs/libTKPrim-eb1262b3.so.7.7.0 +0 -0
  48. topologicpy/bin/linux/topologic.libs/libTKShHealing-e67e5cc7.so.7.7.0 +0 -0
  49. topologicpy/bin/linux/topologic.libs/libTKTopAlgo-e4c96c33.so.7.7.0 +0 -0
  50. topologicpy/bin/linux/topologic.libs/libTKernel-fb7fe3b7.so.7.7.0 +0 -0
  51. topologicpy/bin/linux/topologic.libs/libgcc_s-32c1665e.so.1 +0 -0
  52. topologicpy/bin/linux/topologic.libs/libstdc++-672d7b41.so.6.0.30 +0 -0
  53. topologicpy/bin/windows/topologic/TKBO-f6b191de.dll +0 -0
  54. topologicpy/bin/windows/topologic/TKBRep-e56a600e.dll +0 -0
  55. topologicpy/bin/windows/topologic/TKBool-7b8d47ae.dll +0 -0
  56. topologicpy/bin/windows/topologic/TKFillet-0ddbf0a8.dll +0 -0
  57. topologicpy/bin/windows/topologic/TKG2d-2e2dee3d.dll +0 -0
  58. topologicpy/bin/windows/topologic/TKG3d-6674513d.dll +0 -0
  59. topologicpy/bin/windows/topologic/TKGeomAlgo-d240e370.dll +0 -0
  60. topologicpy/bin/windows/topologic/TKGeomBase-df87aba5.dll +0 -0
  61. topologicpy/bin/windows/topologic/TKMath-45bd625a.dll +0 -0
  62. topologicpy/bin/windows/topologic/TKMesh-d6e826b1.dll +0 -0
  63. topologicpy/bin/windows/topologic/TKOffset-79b9cc94.dll +0 -0
  64. topologicpy/bin/windows/topologic/TKPrim-aa430a86.dll +0 -0
  65. topologicpy/bin/windows/topologic/TKShHealing-bb48be89.dll +0 -0
  66. topologicpy/bin/windows/topologic/TKTopAlgo-7d0d1e22.dll +0 -0
  67. topologicpy/bin/windows/topologic/TKernel-08c8cfbb.dll +0 -0
  68. topologicpy/bin/windows/topologic/__init__.py +2 -0
  69. topologicpy/bin/windows/topologic/topologic.cp310-win_amd64.pyd +0 -0
  70. topologicpy/bin/windows/topologic/topologic.cp311-win_amd64.pyd +0 -0
  71. topologicpy/bin/windows/topologic/topologic.cp38-win_amd64.pyd +0 -0
  72. topologicpy/bin/windows/topologic/topologic.cp39-win_amd64.pyd +0 -0
  73. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/METADATA +1 -1
  74. topologicpy-0.4.9.dist-info/RECORD +77 -0
  75. topologicpy-0.4.9.dist-info/top_level.txt +1 -0
  76. topologicpy-0.4.8.dist-info/RECORD +0 -5
  77. topologicpy-0.4.8.dist-info/top_level.txt +0 -1
  78. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/LICENSE +0 -0
  79. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/WHEEL +0 -0
topologicpy/Plotly.py ADDED
@@ -0,0 +1,1396 @@
1
+ import topologicpy
2
+ import topologic
3
+ import plotly
4
+ import plotly.graph_objects as go
5
+ from topologicpy.Vertex import Vertex
6
+ from topologicpy.Edge import Edge
7
+ from topologicpy.Wire import Wire
8
+ from topologicpy.Face import Face
9
+ from topologicpy.Cell import Cell
10
+ from topologicpy.CellComplex import CellComplex
11
+ from topologicpy.Cluster import Cluster
12
+ from topologicpy.Topology import Topology
13
+ import numpy as np
14
+
15
+ class Plotly:
16
+ @staticmethod
17
+ def AddColorBar(figure, values=[], nTicks=5, xPosition=-0.15, width=15, outlineWidth=0, title="", subTitle="", units="", colorScale="viridis", mantissa=4):
18
+ """
19
+ Adds a color bar to the input figure
20
+
21
+ Parameters
22
+ ----------
23
+ figure : plotly.graph_objs._figure.Figure
24
+ The input plotly figure.
25
+ values : list , optional
26
+ The input list of values to use for the color bar. The default is [].
27
+ nTicks : int , optional
28
+ The number of ticks to use on the color bar. The default is 5.
29
+ xPosition : float , optional
30
+ The x location of the color bar. The default is -0.15.
31
+ width : int , optional
32
+ The width in pixels of the color bar. The default is 15
33
+ outlineWidth : int , optional
34
+ The width in pixels of the outline of the color bar. The default is 0.
35
+ title : str , optional
36
+ The title of the color bar. The default is "".
37
+ subTitle : str , optional
38
+ The subtitle of the color bar. The default is "".
39
+ units: str , optional
40
+ The units used in the color bar. The default is ""
41
+ colorScale : str , optional
42
+ The desired type of plotly color scales to use (e.g. "viridis", "plasma"). The default is "viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
43
+ mantissa : int , optional
44
+ The desired length of the mantissa for the values listed on the color bar. The default is 4.
45
+ Returns
46
+ -------
47
+ plotly.graph_objs._figure.Figure
48
+ The input figure with the color bar added.
49
+
50
+ """
51
+ if not isinstance(figure, plotly.graph_objs._figure.Figure):
52
+ return None
53
+ if units:
54
+ units = "Units: "+units
55
+ minValue = min(values)
56
+ maxValue = max(values)
57
+ step = (maxValue - minValue)/float(nTicks-1)
58
+ r = [round(minValue+i*step, mantissa) for i in range(nTicks)]
59
+ r[-1] = round(maxValue, mantissa)
60
+ # Define the minimum and maximum range of the colorbar
61
+ rs = [str(x) for x in r]
62
+
63
+ # Define the colorbar as a trace with no data, x or y coordinates
64
+ colorbar_trace = go.Scatter(
65
+ x=[0],
66
+ y=[0],
67
+ mode="markers",
68
+ showlegend=False,
69
+ marker=dict(
70
+ size=0,
71
+ colorscale=colorScale, # choose the colorscale
72
+ cmin=minValue,
73
+ cmax=maxValue,
74
+ color=['rgba(0,0,0,0)'],
75
+ colorbar=dict(
76
+ x=xPosition,
77
+ title="<b>"+title+"</b><br>"+subTitle+"<br>"+units, # title of the colorbar
78
+ ticks="outside", # position of the ticks
79
+ tickvals=r, # values of the ticks
80
+ ticktext=rs, # text of the ticks
81
+ tickmode="array",
82
+ thickness=width,
83
+ outlinewidth=outlineWidth,
84
+
85
+ )
86
+ )
87
+ )
88
+ figure.add_trace(colorbar_trace)
89
+ return figure
90
+
91
+ @staticmethod
92
+ def Colors():
93
+ """
94
+ Returns the list of named CSS colors that plotly can use.
95
+
96
+ Returns
97
+ -------
98
+ list
99
+ The list of named CSS colors.
100
+ """
101
+ return ["aliceblue","antiquewhite","aqua",
102
+ "aquamarine","azure","beige",
103
+ "bisque","black","blanchedalmond",
104
+ "blue","blueviolet","brown",
105
+ "burlywood","cadetblue",
106
+ "chartreuse","chocolate",
107
+ "coral","cornflowerblue","cornsilk",
108
+ "crimson","cyan","darkblue",
109
+ "darkcyan","darkgoldenrod","darkgray",
110
+ "darkgrey","darkgreen","darkkhaki",
111
+ "darkmagenta","darkolivegreen","darkorange",
112
+ "darkorchid","darkred","darksalmon",
113
+ "darkseagreen","darkslateblue","darkslategray",
114
+ "darkslategrey","darkturquoise","darkviolet",
115
+ "deeppink","deepskyblue","dimgray",
116
+ "dimgrey","dodgerblue","firebrick",
117
+ "floralwhite","forestgreen","fuchsia",
118
+ "gainsboro","ghostwhite","gold",
119
+ "goldenrod","gray","grey",
120
+ "green"," greenyellow","honeydew",
121
+ "hotpink","indianred","indigo",
122
+ "ivory","khaki","lavender",
123
+ "lavenderblush","lawngreen","lemonchiffon",
124
+ "lightblue","lightcoral","lightcyan",
125
+ "lightgoldenrodyellow","lightgray","lightgrey",
126
+ "lightgreen","lightpink","lightsalmon",
127
+ "lightseagreen","lightskyblue","lightslategray",
128
+ "lightslategrey","lightsteelblue","lightyellow",
129
+ "lime","limegreen","linen",
130
+ "magenta","maroon","mediumaquamarine",
131
+ "mediumblue","mediumorchid","mediumpurple",
132
+ "mediumseagreen","mediumslateblue","mediumspringgreen",
133
+ "mediumturquoise","mediumvioletred","midnightblue",
134
+ "mintcream","mistyrose","moccasin",
135
+ "navajowhite","navy","oldlace",
136
+ "olive","olivedrab","orange",
137
+ "orangered","orchid","palegoldenrod",
138
+ "palegreen","paleturquoise","palevioletred",
139
+ "papayawhip","peachpuff","peru",
140
+ "pink","plum","powderblue",
141
+ "purple","red","rosybrown",
142
+ "royalblue","rebeccapurple","saddlebrown",
143
+ "salmon","sandybrown","seagreen",
144
+ "seashell","sienna","silver",
145
+ "skyblue","slateblue","slategray",
146
+ "slategrey","snow","springgreen",
147
+ "steelblue","tan","teal",
148
+ "thistle","tomato","turquoise",
149
+ "violet","wheat","white",
150
+ "whitesmoke","yellow","yellowgreen"]
151
+
152
+
153
+ @staticmethod
154
+ def DataByDGL(data, labels):
155
+ """
156
+ Returns a data frame from the DGL data.
157
+
158
+ Parameters
159
+ ----------
160
+ data : list
161
+ The data to display.
162
+ labels : list
163
+ The labels to use for the data. The data with the labels in this list will be extracted and used in the returned dataFrame.
164
+
165
+ Returns
166
+ -------
167
+ pd.DataFrame
168
+ A pandas dataFrame
169
+
170
+ """
171
+ import pandas as pd
172
+
173
+ if isinstance(data[labels[0]][0], int):
174
+ xAxis_list = list(range(1,data[labels[0]][0]+1))
175
+ else:
176
+ xAxis_list = data[labels[0]][0]
177
+ plot_data = [xAxis_list]
178
+ for i in range(1,len(labels)):
179
+ plot_data.append(data[labels[i]][0][:len(xAxis_list)])
180
+
181
+ dlist = list(map(list, zip(*plot_data)))
182
+ df = pd.DataFrame(dlist, columns=labels)
183
+ return df
184
+
185
+ @staticmethod
186
+ def DataByGraph(graph, vertexColor="white", vertexSize=6, vertexLabelKey=None, vertexGroupKey=None, vertexGroups=[], showVertices=True, edgeColor="black", edgeWidth=1, edgeLabelKey=None, edgeGroupKey=None, edgeGroups=[], showEdges=True):
187
+ """
188
+ Creates plotly vertex and edge data from the input graph.
189
+
190
+ Parameters
191
+ ----------
192
+ graph : topologic.Graph
193
+ The input graph.
194
+ vertexLabelKey : str , optional
195
+ The dictionary key to use to display the vertex label. The default is None.
196
+ vertexGroupKey : str , optional
197
+ The dictionary key to use to display the vertex group. The default is None.
198
+ edgeLabelKey : str , optional
199
+ The dictionary key to use to display the edge label. The default is None.
200
+ edgeGroupKey : str , optional
201
+ The dictionary key to use to display the edge group. The default is None.
202
+ edgeColor : str , optional
203
+ The desired color of the output edges. This can be any plotly color string and may be specified as:
204
+ - A hex string (e.g. '#ff0000')
205
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
206
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
207
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
208
+ - A named CSS color.
209
+ The default is "black".
210
+ edgeWidth : float , optional
211
+ The desired thickness of the output edges. The default is 1.
212
+ vertexColor : str , optional
213
+ The desired color of the output vertices. This can be any plotly color string and may be specified as:
214
+ - A hex string (e.g. '#ff0000')
215
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
216
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
217
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
218
+ - A named CSS color.
219
+ The default is "black".
220
+ vertexSize : float , optional
221
+ The desired size of the vertices. The default is 1.1.
222
+ showEdges : bool , optional
223
+ If set to True the edges will be drawn. Otherwise, they will not be drawn. The default is True.
224
+ showVertices : bool , optional
225
+ If set to True the vertices will be drawn. Otherwise, they will not be drawn. The default is True.
226
+
227
+ Returns
228
+ -------
229
+ list
230
+ The vertex and edge data list.
231
+
232
+ """
233
+ from topologicpy.Vertex import Vertex
234
+ from topologicpy.Edge import Edge
235
+ from topologicpy.Dictionary import Dictionary
236
+ from topologicpy.Topology import Topology
237
+ from topologicpy.Graph import Graph
238
+ import plotly.graph_objs as go
239
+
240
+ if not isinstance(graph, topologic.Graph):
241
+ return None
242
+ v_labels = []
243
+ v_groupList = []
244
+ data = []
245
+ if showVertices:
246
+ vertices = Graph.Vertices(graph)
247
+ if vertexLabelKey or vertexGroupKey:
248
+ for v in vertices:
249
+ Xn=[Vertex.X(v) for v in vertices] # x-coordinates of nodes
250
+ Yn=[Vertex.Y(v) for v in vertices] # y-coordinates of nodes
251
+ Zn=[Vertex.Z(v) for v in vertices] # x-coordinates of nodes
252
+ v_label = ""
253
+ v_group = ""
254
+ d = Topology.Dictionary(v)
255
+ if d:
256
+ try:
257
+ v_label = str(Dictionary.ValueAtKey(d, key=vertexLabelKey)) or ""
258
+ except:
259
+ v_label = ""
260
+ try:
261
+ v_group = str(Dictionary.ValueAtKey(d, key=vertexGroupKey)) or ""
262
+ except:
263
+ v_group = ""
264
+ try:
265
+ v_groupList.append(vertexGroups.index(v_group))
266
+ except:
267
+ v_groupList.append(len(vertexGroups))
268
+ if not v_label == "" and not v_group == "":
269
+ v_label = v_label+" ("+v_group+")"
270
+ v_labels.append(v_label)
271
+ else:
272
+ for v in vertices:
273
+ Xn=[Vertex.X(v) for v in vertices] # x-coordinates of nodes
274
+ Yn=[Vertex.Y(v) for v in vertices] # y-coordinates of nodes
275
+ Zn=[Vertex.Z(v) for v in vertices] # x-coordinates of nodes
276
+ if len(list(set(v_groupList))) < 2:
277
+ v_groupList = vertexColor
278
+ if len(v_labels) < 1:
279
+ v_labels = ""
280
+ v_trace=go.Scatter3d(x=Xn,
281
+ y=Yn,
282
+ z=Zn,
283
+ mode='markers',
284
+ name='Graph Vertices',
285
+ legendgroup=4,
286
+ legendrank=4,
287
+ marker=dict(symbol='circle',
288
+ size=vertexSize,
289
+ color=v_groupList,
290
+ colorscale='Viridis',
291
+ line=dict(color=edgeColor, width=0.5)
292
+ ),
293
+ text=v_labels,
294
+ hoverinfo='text'
295
+ )
296
+ data.append(v_trace)
297
+
298
+ if showEdges:
299
+ Xe=[]
300
+ Ye=[]
301
+ Ze=[]
302
+ e_labels = []
303
+ e_groupList = []
304
+ edges = Graph.Edges(graph)
305
+
306
+ if edgeLabelKey or edgeGroupKey:
307
+ for e in edges:
308
+ sv = Edge.StartVertex(e)
309
+ ev = Edge.EndVertex(e)
310
+ Xe+=[Vertex.X(sv),Vertex.X(ev), None] # x-coordinates of edge ends
311
+ Ye+=[Vertex.Y(sv),Vertex.Y(ev), None] # y-coordinates of edge ends
312
+ Ze+=[Vertex.Z(sv),Vertex.Z(ev), None] # z-coordinates of edge ends
313
+ e_label = ""
314
+ e_group = ""
315
+ d = Topology.Dictionary(e)
316
+ if d:
317
+ try:
318
+ e_label = str(Dictionary.ValueAtKey(d, key=edgeLabelKey)) or ""
319
+ except:
320
+ e_label = ""
321
+ try:
322
+ e_group = str(Dictionary.ValueAtKey(d, key=edgeGroupKey)) or ""
323
+ except:
324
+ e_group = ""
325
+ try:
326
+ e_groupList.append(edgeGroups.index(e_group))
327
+ except:
328
+ e_groupList.append(len(edgeGroups))
329
+ if not e_label == "" and not e_group == "":
330
+ e_label = e_label+" ("+e_group+")"
331
+ e_labels.append(e_label)
332
+ else:
333
+ for e in edges:
334
+ sv = Edge.StartVertex(e)
335
+ ev = Edge.EndVertex(e)
336
+ Xe+=[Vertex.X(sv),Vertex.X(ev), None] # x-coordinates of edge ends
337
+ Ye+=[Vertex.Y(sv),Vertex.Y(ev), None] # y-coordinates of edge ends
338
+ Ze+=[Vertex.Z(sv),Vertex.Z(ev), None] # z-coordinates of edge ends
339
+
340
+ if len(list(set(e_groupList))) < 2:
341
+ e_groupList = edgeColor
342
+ if len(e_labels) < 1:
343
+ e_labels = ""
344
+
345
+ e_trace=go.Scatter3d(x=Xe,
346
+ y=Ye,
347
+ z=Ze,
348
+ mode='lines',
349
+ name='Graph Edges',
350
+ legendgroup=5,
351
+ legendrank=5,
352
+ line=dict(color=e_groupList, width=edgeWidth),
353
+ text=e_labels,
354
+ hoverinfo='text'
355
+ )
356
+ data.append(e_trace)
357
+
358
+ return data
359
+
360
+ @staticmethod
361
+ def DataByTopology(topology,
362
+ showVertices=True, vertexSize=1.1, vertexColor="black",
363
+ vertexLabelKey=None, vertexGroupKey=None, vertexGroups=[],
364
+ vertexMinGroup=None, vertexMaxGroup=None,
365
+ showVertexLegend=False, vertexLegendLabel="Topology Vertices", vertexLegendRank=1,
366
+ vertexLegendGroup=1,
367
+ showEdges=True, edgeWidth=1, edgeColor="black",
368
+ edgeLabelKey=None, edgeGroupKey=None, edgeGroups=[],
369
+ edgeMinGroup=None, edgeMaxGroup=None,
370
+ showEdgeLegend=False, edgeLegendLabel="Topology Edges", edgeLegendRank=2,
371
+ edgeLegendGroup=2,
372
+ showFaces=True, faceOpacity=0.5, faceColor="white",
373
+ faceLabelKey=None, faceGroupKey=None, faceGroups=[],
374
+ faceMinGroup=None, faceMaxGroup=None,
375
+ showFaceLegend=False, faceLegendLabel="Topology Faces", faceLegendRank=3,
376
+ faceLegendGroup=3,
377
+ intensityKey=None, colorScale="Viridis"):
378
+ """
379
+ Creates plotly face, edge, and vertex data.
380
+
381
+ Parameters
382
+ ----------
383
+ topology : topologic.Topology
384
+ The input topology. This must contain faces and or edges.
385
+
386
+ showVertices : bool , optional
387
+ If set to True the vertices will be drawn. Otherwise, they will not be drawn. The default is True.
388
+ vertexSize : float , optional
389
+ The desired size of the vertices. The default is 1.1.
390
+ vertexColor : str , optional
391
+ The desired color of the output vertices. This can be any plotly color string and may be specified as:
392
+ - A hex string (e.g. '#ff0000')
393
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
394
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
395
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
396
+ - A named CSS color.
397
+ The default is "black".
398
+ vertexLabelKey : str , optional
399
+ The dictionary key to use to display the vertex label. The default is None.
400
+ vertexGroupKey : str , optional
401
+ The dictionary key to use to display the vertex group. The default is None.
402
+ vertexGroups : list , optional
403
+ The list of vertex groups against which to index the color of the vertex. The default is [].
404
+ vertexMinGroup : int or float , optional
405
+ For numeric vertexGroups, vertexMinGroup is the desired minimum value for the scaling of colors. This should match the type of value associated with the vertexGroupKey. If set to None, it is set to the minimum value in vertexGroups. The default is None.
406
+ edgeMaxGroup : int or float , optional
407
+ For numeric vertexGroups, vertexMaxGroup is the desired maximum value for the scaling of colors. This should match the type of value associated with the vertexGroupKey. If set to None, it is set to the maximum value in vertexGroups. The default is None.
408
+ showVertexLegend : bool, optional
409
+ If set to True, the legend for the vertices of this topology is shown. Otherwise, it isn't. The default is False.
410
+ vertexLegendLabel : str , optional
411
+ The legend label string used to identify vertices. The default is "Topology Vertices".
412
+ vertexLegendRank : int , optional
413
+ The legend rank order of the vertices of this topology. The default is 1.
414
+ vertexLegendGroup : int , optional
415
+ The number of the vertex legend group to which the vertices of this topology belong. The default is 1.
416
+
417
+ showEdges : bool , optional
418
+ If set to True the edges will be drawn. Otherwise, they will not be drawn. The default is True.
419
+ edgeWidth : float , optional
420
+ The desired thickness of the output edges. The default is 1.
421
+ edgeColor : str , optional
422
+ The desired color of the output edges. This can be any plotly color string and may be specified as:
423
+ - A hex string (e.g. '#ff0000')
424
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
425
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
426
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
427
+ - A named CSS color.
428
+ The default is "black".
429
+ edgeLabelKey : str , optional
430
+ The dictionary key to use to display the edge label. The default is None.
431
+ edgeGroupKey : str , optional
432
+ The dictionary key to use to display the edge group. The default is None.
433
+ edgeGroups : list , optional
434
+ The list of edge groups against which to index the color of the edge. The default is [].
435
+ edgeMinGroup : int or float , optional
436
+ For numeric edgeGroups, edgeMinGroup is the desired minimum value for the scaling of colors. This should match the type of value associated with the edgeGroupKey. If set to None, it is set to the minimum value in edgeGroups. The default is None.
437
+ edgeMaxGroup : int or float , optional
438
+ For numeric edgeGroups, edgeMaxGroup is the desired maximum value for the scaling of colors. This should match the type of value associated with the edgeGroupKey. If set to None, it is set to the maximum value in edgeGroups. The default is None.
439
+ showEdgeLegend : bool, optional
440
+ If set to True, the legend for the edges of this topology is shown. Otherwise, it isn't. The default is False.
441
+ edgeLegendLabel : str , optional
442
+ The legend label string used to identify edges. The default is "Topology Edges".
443
+ edgeLegendRank : int , optional
444
+ The legend rank order of the edges of this topology. The default is 2.
445
+ edgeLegendGroup : int , optional
446
+ The number of the edge legend group to which the edges of this topology belong. The default is 2.
447
+
448
+ showFaces : bool , optional
449
+ If set to True the faces will be drawn. Otherwise, they will not be drawn. The default is True.
450
+ faceOpacity : float , optional
451
+ The desired opacity of the output faces (0=transparent, 1=opaque). The default is 0.5.
452
+ faceColor : str , optional
453
+ The desired color of the output faces. This can be any plotly color string and may be specified as:
454
+ - A hex string (e.g. '#ff0000')
455
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
456
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
457
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
458
+ - A named CSS color.
459
+ The default is "white".
460
+ faceLabelKey : str , optional
461
+ The dictionary key to use to display the face label. The default is None.
462
+ faceGroupKey : str , optional
463
+ The dictionary key to use to display the face group. The default is None.
464
+ faceGroups : list , optional
465
+ The list of face groups against which to index the color of the face. This can bhave numeric or string values. This should match the type of value associated with the faceGroupKey. The default is [].
466
+ faceMinGroup : int or float , optional
467
+ For numeric faceGroups, minGroup is the desired minimum value for the scaling of colors. This should match the type of value associated with the faceGroupKey. If set to None, it is set to the minimum value in faceGroups. The default is None.
468
+ faceMaxGroup : int or float , optional
469
+ For numeric faceGroups, maxGroup is the desired maximum value for the scaling of colors. This should match the type of value associated with the faceGroupKey. If set to None, it is set to the maximum value in faceGroups. The default is None.
470
+ showFaceLegend : bool, optional
471
+ If set to True, the legend for the faces of this topology is shown. Otherwise, it isn't. The default is False.
472
+ faceLegendLabel : str , optional
473
+ The legend label string used to idenitfy edges. The default is "Topology Faces".
474
+ faceLegendRank : int , optional
475
+ The legend rank order of the faces of this topology. The default is 3.
476
+ faceLegendGroup : int , optional
477
+ The number of the face legend group to which the faces of this topology belong. The default is 3.
478
+ intensityKey: str, optional
479
+ If not None, the dictionary of each vertex is searched for the value associated with the intensity key. This value is then used to color-code the vertex based on the colorScale. The default is None.
480
+ colorScale : str , optional
481
+ The desired type of plotly color scales to use (e.g. "Viridis", "Plasma"). The default is "Viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
482
+
483
+ Returns
484
+ -------
485
+ list
486
+ The vertex, edge, and face data list.
487
+
488
+ """
489
+ from topologicpy.Topology import Topology
490
+ from topologicpy.Dictionary import Dictionary
491
+ from topologicpy.Color import Color
492
+ def vertexData(vertices, dictionaries=None, color="black", size=1.1, labelKey=None, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Vertices", legendGroup=1, legendRank=1, showLegend=True, colorScale="Viridis"):
493
+ x = []
494
+ y = []
495
+ z = []
496
+ labels = []
497
+ groupList = []
498
+ label = ""
499
+ group = ""
500
+ if labelKey or groupKey:
501
+ if groups:
502
+ if len(groups) > 0:
503
+ if type(groups[0]) == int or type(groups[0]) == float:
504
+ if not minGroup:
505
+ minGroup = min(groups)
506
+ if not maxGroup:
507
+ maxGroup = max(groups)
508
+ else:
509
+ minGroup = 0
510
+ maxGroup = len(groups) - 1
511
+ else:
512
+ minGroup = 0
513
+ maxGroup = 1
514
+ for m, v in enumerate(vertices):
515
+ x.append(v[0])
516
+ y.append(v[1])
517
+ z.append(v[2])
518
+ label = ""
519
+ group = ""
520
+ if len(dictionaries) > 0:
521
+ d = dictionaries[m]
522
+ if d:
523
+ try:
524
+ label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
525
+ except:
526
+ label = ""
527
+ try:
528
+ group = Dictionary.ValueAtKey(d, key=groupKey) or None
529
+ except:
530
+ group = ""
531
+ try:
532
+ if type(group) == int or type(group) == float:
533
+ if group < minGroup:
534
+ group = minGroup
535
+ if group > maxGroup:
536
+ group = maxGroup
537
+ color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
538
+ else:
539
+ color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
540
+ color = "rgb("+str(color[0])+","+str(color[1])+","+str(color[2])+")"
541
+ groupList.append(color)
542
+ except:
543
+ groupList.append(len(groups))
544
+ labels.append(label)
545
+ else:
546
+ for v in vertices:
547
+ x.append(v[0])
548
+ y.append(v[1])
549
+ z.append(v[2])
550
+
551
+ if len(list(set(groupList))) < 2:
552
+ groupList = color
553
+ if len(labels) < 1:
554
+ labels = ""
555
+ return go.Scatter3d(x=x,
556
+ y=y,
557
+ z=z,
558
+ name=legendLabel,
559
+ showlegend=showLegend,
560
+ marker=dict(color=groupList, size=vertexSize),
561
+ mode='markers',
562
+ legendgroup=legendGroup,
563
+ legendrank=legendRank,
564
+ text=labels,
565
+ hoverinfo='text',
566
+ hovertext=labels
567
+ )
568
+
569
+ def edgeData(vertices, edges, dictionaries=None, color="black", width=1, labelKey=None, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Edges", legendGroup=2, legendRank=2, showLegend=True, colorScale="Viridis"):
570
+ x = []
571
+ y = []
572
+ z = []
573
+ labels = []
574
+ groupList = []
575
+ label = ""
576
+ group = ""
577
+ if labelKey or groupKey:
578
+ if groups:
579
+ if len(groups) > 0:
580
+ if type(groups[0]) == int or type(groups[0]) == float:
581
+ if not minGroup:
582
+ minGroup = min(groups)
583
+ if not maxGroup:
584
+ maxGroup = max(groups)
585
+ else:
586
+ minGroup = 0
587
+ maxGroup = len(groups) - 1
588
+ else:
589
+ minGroup = 0
590
+ maxGroup = 1
591
+ for m, e in enumerate(edges):
592
+ sv = vertices[e[0]]
593
+ ev = vertices[e[1]]
594
+ x+=[sv[0],ev[0], None] # x-coordinates of edge ends
595
+ y+=[sv[1],ev[1], None] # y-coordinates of edge ends
596
+ z+=[sv[2],ev[2], None] # z-coordinates of edge ends
597
+ label = ""
598
+ group = ""
599
+ if len(dictionaries) > 0:
600
+ d = dictionaries[m]
601
+ if d:
602
+ try:
603
+ label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
604
+ except:
605
+ label = ""
606
+ try:
607
+ group = Dictionary.ValueAtKey(d, key=groupKey) or None
608
+ except:
609
+ group = ""
610
+ try:
611
+ if type(group) == int or type(group) == float:
612
+ if group < minGroup:
613
+ group = minGroup
614
+ if group > maxGroup:
615
+ group = maxGroup
616
+ color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
617
+ else:
618
+ color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
619
+ color = "rgb("+str(color[0])+","+str(color[1])+","+str(color[2])+")"
620
+ groupList.append(color)
621
+ except:
622
+ groupList.append(len(groups))
623
+ labels.append(label)
624
+ else:
625
+ for e in edges:
626
+ sv = vertices[e[0]]
627
+ ev = vertices[e[1]]
628
+ x+=[sv[0],ev[0], None] # x-coordinates of edge ends
629
+ y+=[sv[1],ev[1], None] # y-coordinates of edge ends
630
+ z+=[sv[2],ev[2], None] # z-coordinates of edge ends
631
+
632
+ if len(list(set(groupList))) < 2:
633
+ groupList = color
634
+ if len(labels) < 1:
635
+ labels = ""
636
+ return go.Scatter3d(x=x,
637
+ y=y,
638
+ z=z,
639
+ name=legendLabel,
640
+ showlegend=showLegend,
641
+ marker_size=0,
642
+ mode="lines",
643
+ line=dict(color=groupList, width=edgeWidth),
644
+ legendgroup=legendGroup,
645
+ legendrank=legendRank,
646
+ text=labels,
647
+ hoverinfo='text')
648
+
649
+
650
+ def faceData(vertices, faces, dictionaries=None, color="white", opacity=0.5, labelKey=None, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Faces", legendGroup=3, legendRank=3, showLegend=True, intensities=None, colorScale="Viridis"):
651
+ x = []
652
+ y = []
653
+ z = []
654
+ for v in vertices:
655
+ x.append(v[0])
656
+ y.append(v[1])
657
+ z.append(v[2])
658
+ i = []
659
+ j = []
660
+ k = []
661
+ labels = []
662
+ groupList = []
663
+ label = ""
664
+ group = ""
665
+ if labelKey or groupKey:
666
+ if groups:
667
+ if len(groups) > 0:
668
+ if type(groups[0]) == int or type(groups[0]) == float:
669
+ if not minGroup:
670
+ minGroup = min(groups)
671
+ if not maxGroup:
672
+ maxGroup = max(groups)
673
+ else:
674
+ minGroup = 0
675
+ maxGroup = len(groups) - 1
676
+ else:
677
+ minGroup = 0
678
+ maxGroup = 1
679
+ for m, f in enumerate(faces):
680
+ i.append(f[0])
681
+ j.append(f[1])
682
+ k.append(f[2])
683
+ label = ""
684
+ group = ""
685
+ if len(dictionaries) > 0:
686
+ d = dictionaries[m]
687
+ if d:
688
+ try:
689
+ label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
690
+ except:
691
+ label = ""
692
+ try:
693
+ group = Dictionary.ValueAtKey(d, key=groupKey) or None
694
+ except:
695
+ group = ""
696
+ try:
697
+ if type(group) == int or type(group) == float:
698
+ if group < minGroup:
699
+ group = minGroup
700
+ if group > maxGroup:
701
+ group = maxGroup
702
+ color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
703
+ else:
704
+ color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
705
+ color = "rgb("+str(color[0])+","+str(color[1])+","+str(color[2])+")"
706
+ groupList.append(color)
707
+ except:
708
+ groupList.append(len(groups))
709
+ labels.append(label)
710
+ else:
711
+ for f in faces:
712
+ i.append(f[0])
713
+ j.append(f[1])
714
+ k.append(f[2])
715
+
716
+ if len(list(set(groupList))) < 2:
717
+ groupList = None
718
+ if len(labels) < 1:
719
+ labels = ""
720
+ trace = go.Mesh3d(
721
+ x = x,
722
+ y = y,
723
+ z = z,
724
+ i = i,
725
+ j = j,
726
+ k = k,
727
+ name = legendLabel,
728
+ showlegend = showLegend,
729
+ legendgroup = legendGroup,
730
+ legendrank = legendRank,
731
+ color = color,
732
+ facecolor = groupList,
733
+ colorscale = colorScale,
734
+ intensity = intensities,
735
+ opacity = opacity,
736
+ hoverinfo = 'text',
737
+ text = labels,
738
+ hovertext = labels,
739
+ flatshading = True,
740
+ showscale = False,
741
+ lighting = {"facenormalsepsilon": 0},
742
+ )
743
+ return trace
744
+
745
+ from topologicpy.Cluster import Cluster
746
+ from topologicpy.Topology import Topology
747
+ from topologicpy.Dictionary import Dictionary
748
+ if not isinstance(topology, topologic.Topology):
749
+ return None
750
+ e_dictionaries = None
751
+ if edgeLabelKey or edgeGroupKey:
752
+ e_dictionaries = []
753
+ tp_edges = Topology.SubTopologies(topology, subTopologyType="edge")
754
+ for tp_edge in tp_edges:
755
+ e_dictionaries.append(Topology.Dictionary(tp_edge))
756
+
757
+ f_dictionaries = None
758
+ if faceLabelKey or faceGroupKey:
759
+ f_dictionaries = []
760
+ tp_faces = Topology.SubTopologies(topology, subTopologyType="face")
761
+ for tp_face in tp_faces:
762
+ f_dictionaries.append(Topology.Dictionary(tp_face))
763
+
764
+ data = []
765
+ tp_verts = Topology.SubTopologies(topology, subTopologyType="vertex")
766
+ vertices = []
767
+ v_dictionaries = []
768
+ intensities = []
769
+ for i, tp_v in enumerate(tp_verts):
770
+ vertices.append([tp_v.X(), tp_v.Y(), tp_v.Z()])
771
+ d = Topology.Dictionary(tp_v)
772
+ if intensityKey:
773
+ if d:
774
+ v = Dictionary.ValueAtKey(d, key=intensityKey)
775
+ if not v == None:
776
+ intensities.append(v)
777
+ else:
778
+ intensities.append(0)
779
+ else:
780
+ intensities.append(0)
781
+ else:
782
+ intensities = None
783
+ if vertexLabelKey or vertexGroupKey:
784
+ v_dictionaries.append(d)
785
+ #if intensities:
786
+ #intensities = [float(m)/max(intensities) for m in intensities]
787
+ if showVertices:
788
+ data.append(vertexData(vertices, dictionaries=v_dictionaries, color=vertexColor, size=vertexSize, labelKey=vertexLabelKey, groupKey=vertexGroupKey, minGroup=vertexMinGroup, maxGroup=vertexMaxGroup, groups=vertexGroups, legendLabel=vertexLegendLabel, legendGroup=vertexLegendGroup, legendRank=vertexLegendRank, showLegend=showVertexLegend, colorScale=colorScale))
789
+ if showEdges and topology.Type() > topologic.Vertex.Type():
790
+ tp_edges = Topology.SubTopologies(topology, subTopologyType="edge")
791
+ edges = []
792
+ for tp_edge in tp_edges:
793
+ sv = Edge.StartVertex(tp_edge)
794
+ si = Vertex.Index(sv, tp_verts)
795
+ ev = Edge.EndVertex(tp_edge)
796
+ ei = Vertex.Index(ev, tp_verts)
797
+ edges.append([si, ei])
798
+ data.append(edgeData(vertices, edges, dictionaries=e_dictionaries, color=edgeColor, width=edgeWidth, labelKey=edgeLabelKey, groupKey=edgeGroupKey, minGroup=edgeMinGroup, maxGroup=edgeMaxGroup, groups=edgeGroups, legendLabel=edgeLegendLabel, legendGroup=edgeLegendGroup, legendRank=edgeLegendRank, showLegend=showEdgeLegend, colorScale=colorScale))
799
+ if showFaces and topology.Type() >= topologic.Face.Type():
800
+ tp_faces = Topology.SubTopologies(topology, subTopologyType="face")
801
+ triangles = []
802
+ f_dictionaries = []
803
+ for tp_face in tp_faces:
804
+ temp_faces = Face.Triangulate(tp_face)
805
+ for tri in temp_faces:
806
+ triangles.append(tri)
807
+ if faceLabelKey or faceGroupKey:
808
+ f_dictionaries.append(Topology.Dictionary(tp_face))
809
+ faces = []
810
+ for tri in triangles:
811
+ w = Face.ExternalBoundary(tri)
812
+ w_vertices = Topology.SubTopologies(w, subTopologyType="vertex")
813
+ temp_f = []
814
+ for w_v in w_vertices:
815
+ i = Vertex.Index(vertex=w_v, vertices=tp_verts, tolerance=0.01)
816
+ temp_f.append(i)
817
+ faces.append(temp_f)
818
+ data.append(faceData(vertices, faces, dictionaries=f_dictionaries, color=faceColor, opacity=faceOpacity, labelKey=faceLabelKey, groupKey=faceGroupKey, minGroup=faceMinGroup, maxGroup=faceMaxGroup, groups=faceGroups, legendLabel=faceLegendLabel, legendGroup=faceLegendGroup, legendRank=faceLegendRank, showLegend=showFaceLegend, intensities=intensities, colorScale=colorScale))
819
+ return data
820
+
821
+
822
+ @staticmethod
823
+ def FigureByConfusionMatrix(matrix,
824
+ categories=[],
825
+ minValue=None,
826
+ maxValue=None,
827
+ title="Confusion Matrix",
828
+ xTitle = "Actual",
829
+ yTitle = "Predicted",
830
+ width=950,
831
+ height=500,
832
+ showScale = True,
833
+ colorScale='Viridis',
834
+ colorSamples=10,
835
+ backgroundColor='rgba(0,0,0,0)',
836
+ marginLeft=0,
837
+ marginRight=0,
838
+ marginTop=40,
839
+ marginBottom=0):
840
+ """
841
+ Returns a Plotly Figure of the input confusion matrix. Actual categories are displayed on the X-Axis, Predicted categories are displayed on the Y-Axis.
842
+
843
+ Parameters
844
+ ----------
845
+ matrix : list or numpy.array
846
+ The matrix to display.
847
+ categories : list
848
+ The list of categories to use on the X and Y axes.
849
+ minValue : float , optional
850
+ The desired minimum value to use for the color scale. If set to None, the minmum value found in the input matrix will be used. The default is None.
851
+ maxValue : float , optional
852
+ The desired maximum value to use for the color scale. If set to None, the maximum value found in the input matrix will be used. The default is None.
853
+ title : str , optional
854
+ The desired title to display. The default is "Confusion Matrix".
855
+ xTitle : str , optional
856
+ The desired X-axis title to display. The default is "Actual".
857
+ yTitle : str , optional
858
+ The desired Y-axis title to display. The default is "Predicted".
859
+ width : int , optional
860
+ The desired width of the figure. The default is 950.
861
+ height : int , optional
862
+ The desired height of the figure. The default is 500.
863
+ showScale : bool , optional
864
+ If set to True, a color scale is shown on the right side of the figure. The default is True.
865
+ colorScale : str , optional
866
+ The desired type of plotly color scales to use (e.g. "Viridis", "Plasma"). The default is "Viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
867
+ colorSamples : int , optional
868
+ The number of discrete color samples to use for displaying the data. The default is 10.
869
+ backgroundColor : str , optional
870
+ The desired background color. This can be any plotly color string and may be specified as:
871
+ - A hex string (e.g. '#ff0000')
872
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
873
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
874
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
875
+ - A named CSS color.
876
+ The default is 'rgba(0,0,0,0)' (transparent).
877
+ marginLeft : int , optional
878
+ The desired left margin in pixels. The default is 0.
879
+ marginRight : int , optional
880
+ The desired right margin in pixels. The default is 0.
881
+ marginTop : int , optional
882
+ The desired top margin in pixels. The default is 40.
883
+ marginBottom : int , optional
884
+ The desired bottom margin in pixels. The default is 0.
885
+
886
+ """
887
+
888
+ return Plotly.FigureByMatrix(matrix,
889
+ xCategories=categories,
890
+ minValue=minValue,
891
+ maxValue=maxValue,
892
+ title=title,
893
+ xTitle=xTitle,
894
+ yTitle=yTitle,
895
+ width=width,
896
+ height=height,
897
+ showScale=showScale,
898
+ colorScale=colorScale,
899
+ colorSamples=colorSamples,
900
+ backgroundColor=backgroundColor,
901
+ marginLeft=marginLeft,
902
+ marginRight=marginRight,
903
+ marginTop=marginTop,
904
+ marginBottom=marginBottom)
905
+
906
+ @staticmethod
907
+ def FigureByMatrix(matrix,
908
+ xCategories=[],
909
+ yCategories=[],
910
+ minValue=None,
911
+ maxValue=None,
912
+ title="Matrix",
913
+ xTitle = "X Axis",
914
+ yTitle = "Y Axis",
915
+ width=950,
916
+ height=950,
917
+ showScale = False,
918
+ colorScale='gray',
919
+ colorSamples=10,
920
+ backgroundColor='rgba(0,0,0,0)',
921
+ marginLeft=0,
922
+ marginRight=0,
923
+ marginTop=40,
924
+ marginBottom=0):
925
+ """
926
+ Returns a Plotly Figure of the input matrix.
927
+
928
+ Parameters
929
+ ----------
930
+ matrix : list or numpy.array
931
+ The matrix to display.
932
+ categories : list
933
+ The list of categories to use on the X and Y axes.
934
+ minValue : float , optional
935
+ The desired minimum value to use for the color scale. If set to None, the minmum value found in the input matrix will be used. The default is None.
936
+ maxValue : float , optional
937
+ The desired maximum value to use for the color scale. If set to None, the maximum value found in the input matrix will be used. The default is None.
938
+ title : str , optional
939
+ The desired title to display. The default is "Confusion Matrix".
940
+ xTitle : str , optional
941
+ The desired X-axis title to display. The default is "Actual".
942
+ yTitle : str , optional
943
+ The desired Y-axis title to display. The default is "Predicted".
944
+ width : int , optional
945
+ The desired width of the figure. The default is 950.
946
+ height : int , optional
947
+ The desired height of the figure. The default is 500.
948
+ showScale : bool , optional
949
+ If set to True, a color scale is shown on the right side of the figure. The default is True.
950
+ colorScale : str , optional
951
+ The desired type of plotly color scales to use (e.g. "Viridis", "Plasma"). The default is "Viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
952
+ colorSamples : int , optional
953
+ The number of discrete color samples to use for displaying the data. The default is 10.
954
+ backgroundColor : str , optional
955
+ The desired background color. This can be any plotly color string and may be specified as:
956
+ - A hex string (e.g. '#ff0000')
957
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
958
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
959
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
960
+ - A named CSS color.
961
+ The default is 'rgba(0,0,0,0)' (transparent).
962
+ marginLeft : int , optional
963
+ The desired left margin in pixels. The default is 0.
964
+ marginRight : int , optional
965
+ The desired right margin in pixels. The default is 0.
966
+ marginTop : int , optional
967
+ The desired top margin in pixels. The default is 40.
968
+ marginBottom : int , optional
969
+ The desired bottom margin in pixels. The default is 0.
970
+
971
+ """
972
+ #import plotly.figure_factory as ff
973
+ import plotly.graph_objects as go
974
+ import plotly.express as px
975
+
976
+ annotations = []
977
+
978
+ if isinstance(matrix, list):
979
+ matrix = np.array(matrix)
980
+ colors = px.colors.sample_colorscale(colorScale, [n/(colorSamples -1) for n in range(colorSamples)])
981
+
982
+ if not xCategories:
983
+ xCategories = [x for x in range(len(matrix[0]))]
984
+ if not yCategories:
985
+ yCategories = [y for y in range(len(matrix))]
986
+
987
+ if not maxValue or not minValue:
988
+ max_values = []
989
+ min_values = []
990
+ for i in range(len(matrix)):
991
+ row = matrix[i]
992
+ max_values.append(max(row))
993
+ min_values.append(min(row))
994
+ for j, value in enumerate(row):
995
+ annotations.append(
996
+ {
997
+ "x": xCategories[j],
998
+ "y": yCategories[i],
999
+ "font": {"color": "black"},
1000
+ "bgcolor": "white",
1001
+ "opacity": 0.5,
1002
+ "text": str(round(value,2)),
1003
+ "xref": "x1",
1004
+ "yref": "y1",
1005
+ "showarrow": False
1006
+ }
1007
+ )
1008
+ if not minValue:
1009
+ minValueB = min(min_values)
1010
+ if not maxValue:
1011
+ maxValue = max(max_values)
1012
+ else:
1013
+ for i in range(len(matrix)):
1014
+ row = matrix[i]
1015
+ for j, value in enumerate(row):
1016
+ annotations.append(
1017
+ {
1018
+ "x": xCategories[j],
1019
+ "y": yCategories[i],
1020
+ "font": {"color": "black"},
1021
+ "bgcolor": "white",
1022
+ "opacity": 0.5,
1023
+ "text": str(round(value,2)),
1024
+ "xref": "x1",
1025
+ "yref": "y1",
1026
+ "showarrow": False
1027
+ }
1028
+ )
1029
+ new_matrix = []
1030
+ for i in range(len(matrix)):
1031
+ row = matrix[i]
1032
+ new_row = []
1033
+ maxRow = sum(row)
1034
+ for j in range(len(row)):
1035
+ if maxRow == 0:
1036
+ new_row.append(round(0, 3))
1037
+ else:
1038
+ new_row.append(round(float(row[j])/float(maxRow), 3))
1039
+ new_matrix.append(new_row)
1040
+ data = go.Heatmap(z=new_matrix, y=yCategories, x=xCategories, zmin=minValue, zmax=maxValue, showscale=showScale, colorscale=colors)
1041
+
1042
+ layout = {
1043
+ "width": width,
1044
+ "height": height,
1045
+ "title": title,
1046
+ "xaxis": {"title": xTitle},
1047
+ "yaxis": {"title": yTitle},
1048
+ "annotations": annotations,
1049
+ "paper_bgcolor": backgroundColor,
1050
+ "plot_bgcolor": backgroundColor,
1051
+ "margin":dict(l=marginLeft, r=marginRight, t=marginTop, b=marginBottom)
1052
+ }
1053
+ fig = go.Figure(data=data, layout=layout)
1054
+ fig.update_xaxes( tickvals=xCategories)
1055
+ fig.update_yaxes( tickvals=yCategories)
1056
+ return fig
1057
+
1058
+ @staticmethod
1059
+ def FigureByDataFrame(dataFrame,
1060
+ labels=[],
1061
+ width=950,
1062
+ height=500,
1063
+ title="Untitled",
1064
+ xTitle="X Axis",
1065
+ xSpacing=1,
1066
+ yTitle="Y Axis",
1067
+ ySpacing=1.0,
1068
+ useMarkers=False,
1069
+ chartType="Line",
1070
+ backgroundColor='rgba(0,0,0,0)',
1071
+ gridColor = 'lightgray',
1072
+ marginLeft=0,
1073
+ marginRight=0,
1074
+ marginTop=40,
1075
+ marginBottom=0):
1076
+
1077
+ """
1078
+ Returns a Plotly Figure of the input dataframe
1079
+
1080
+ Parameters
1081
+ ----------
1082
+ df : pandas.df
1083
+ The p[andas dataframe to display.
1084
+ data_labels : list
1085
+ The labels to use for the data.
1086
+ width : int , optional
1087
+ The desired width of the figure. The default is 950.
1088
+ height : int , optional
1089
+ The desired height of the figure. The default is 500.
1090
+ title : str , optional
1091
+ The chart title. The default is "Training and Testing Results".
1092
+ xTitle : str , optional
1093
+ The X-axis title. The default is "Epochs".
1094
+ xSpacing : float , optional
1095
+ The X-axis spacing. The default is 1.0.
1096
+ yTitle : str , optional
1097
+ The Y-axis title. The default is "Accuracy and Loss".
1098
+ ySpacing : float , optional
1099
+ THe Y-axis spacing. The default is 0.1.
1100
+ useMarkers : bool , optional
1101
+ If set to True, markers will be displayed. The default is False.
1102
+ chartType : str , optional
1103
+ The desired type of chart. The options are "Line", "Bar", or "Scatter". It is case insensitive. The default is "Line".
1104
+ backgroundColor : str , optional
1105
+ The desired background color. This can be any plotly color string and may be specified as:
1106
+ - A hex string (e.g. '#ff0000')
1107
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1108
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
1109
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
1110
+ - A named CSS color.
1111
+ The default is 'rgba(0,0,0,0)' (transparent).
1112
+ grid : str , optional
1113
+ The desired background color. This can be any plotly color string and may be specified as:
1114
+ - A hex string (e.g. '#ff0000')
1115
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1116
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
1117
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
1118
+ - A named CSS color.
1119
+ The default is 'lightgray'
1120
+ marginLeft : int , optional
1121
+ The desired left margin in pixels. The default is 0.
1122
+ marginRight : int , optional
1123
+ The desired right margin in pixels. The default is 0.
1124
+ marginTop : int , optional
1125
+ The desired top margin in pixels. The default is 40.
1126
+ marginBottom : int , optional
1127
+ The desired bottom margin in pixels. The default is 0.
1128
+
1129
+ Returns
1130
+ -------
1131
+ None.
1132
+
1133
+ """
1134
+ import plotly.express as px
1135
+
1136
+ if chartType.lower() == "line":
1137
+ figure = px.line(dataFrame, x=labels[0], y=labels[1:], title=title, markers=useMarkers)
1138
+ elif chartType.lower() == "bar":
1139
+ figure = px.bar(dataFrame, x=labels[0], y=labels[1:], title=title)
1140
+ elif chartType.lower() == "scatter":
1141
+ figure = px.scatter(dataFrame, x=labels[0], y=labels[1:], title=title)
1142
+ else:
1143
+ raise NotImplementedError
1144
+
1145
+ layout = {
1146
+ "width": width,
1147
+ "height": height,
1148
+ "title": title,
1149
+ "xaxis": {"title": xTitle, "dtick": xSpacing, 'gridcolor': gridColor},
1150
+ "yaxis": {"title": yTitle, "dtick": ySpacing, 'gridcolor': gridColor},
1151
+ "paper_bgcolor": backgroundColor,
1152
+ "plot_bgcolor": backgroundColor,
1153
+ "margin":dict(l=marginLeft, r=marginRight, t=marginTop, b=marginBottom)
1154
+ }
1155
+ figure.update_layout(layout)
1156
+ return figure
1157
+
1158
+
1159
+ @staticmethod
1160
+ def FigureByData(data, color=None, width=950, height=500, xAxis=False, yAxis=False, zAxis=False, axisSize=1, backgroundColor='rgba(0,0,0,0)', marginLeft=0, marginRight=0, marginTop=20, marginBottom=0):
1161
+ """
1162
+ Creates a plotly figure.
1163
+
1164
+ Parameters
1165
+ ----------
1166
+ data : list
1167
+ The input list of plotly data.
1168
+ width : int , optional
1169
+ The width in pixels of the figure. The default value is 950.
1170
+ height : int , optional
1171
+ The height in pixels of the figure. The default value is 950.
1172
+ xAxis : bool , optional
1173
+ If set to True the x axis is drawn. Otherwise it is not drawn. The default is False.
1174
+ yAxis : bool , optional
1175
+ If set to True the y axis is drawn. Otherwise it is not drawn. The default is False.
1176
+ zAxis : bool , optional
1177
+ If set to True the z axis is drawn. Otherwise it is not drawn. The default is False.
1178
+ axisSize : float , optional
1179
+ The size of the X,Y,Z, axes. The default is 1.
1180
+ backgroundColor : str , optional
1181
+ The desired color of the background. This can be any plotly color string and may be specified as:
1182
+ - A hex string (e.g. '#ff0000')
1183
+ - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1184
+ - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
1185
+ - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
1186
+ - A named CSS color.
1187
+ The default is "rgba(0,0,0,0)".
1188
+ marginLeft : int , optional
1189
+ The size in pixels of the left margin. The default value is 0.
1190
+ marginRight : int , optional
1191
+ The size in pixels of the right margin. The default value is 0.
1192
+ marginTop : int , optional
1193
+ The size in pixels of the top margin. The default value is 20.
1194
+ marginBottom : int , optional
1195
+ The size in pixels of the bottom margin. The default value is 0.
1196
+
1197
+ Returns
1198
+ -------
1199
+ plotly.graph_objs._figure.Figure
1200
+ The created plotly figure.
1201
+
1202
+ """
1203
+ from topologicpy.Vertex import Vertex
1204
+ from topologicpy.Edge import Edge
1205
+ from topologicpy.Wire import Wire
1206
+ if not isinstance(data, list):
1207
+ return None
1208
+
1209
+ v0 = Vertex.ByCoordinates(0,0,0)
1210
+ v1 = Vertex.ByCoordinates(axisSize,0,0)
1211
+ v2 = Vertex.ByCoordinates(0,axisSize,0)
1212
+ v3 = Vertex.ByCoordinates(0,0,axisSize)
1213
+
1214
+ if xAxis:
1215
+ xEdge = Edge.ByVertices([v0,v1])
1216
+ xWire = Wire.ByEdges([xEdge])
1217
+ xData = Plotly.DataByTopology(xWire, edgeColor="red", edgeWidth=6, showFaces=False, showEdges=True, showVertices=False, edgeLegendLabel="X-Axis")
1218
+ data = data + xData
1219
+ if yAxis:
1220
+ yEdge = Edge.ByVertices([v0,v2])
1221
+ yWire = Wire.ByEdges([yEdge])
1222
+ yData = Plotly.DataByTopology(yWire, edgeColor="green", edgeWidth=6, showFaces=False, showEdges=True, showVertices=False, edgeLegendLabel="Y-Axis")
1223
+ data = data + yData
1224
+ if zAxis:
1225
+ zEdge = Edge.ByVertices([v0,v3])
1226
+ zWire = Wire.ByEdges([zEdge])
1227
+ zData = Plotly.DataByTopology(zWire, edgeColor="blue", edgeWidth=6, showFaces=False, showEdges=True, showVertices=False, edgeLegendLabel="Z-Axis")
1228
+ data = data + zData
1229
+
1230
+ figure = go.Figure(data=data)
1231
+ figure.update_layout(
1232
+ width=width,
1233
+ height=height,
1234
+ showlegend=True,
1235
+ scene = dict(
1236
+ xaxis = dict(visible=False),
1237
+ yaxis = dict(visible=False),
1238
+ zaxis =dict(visible=False),
1239
+ ),
1240
+ scene_aspectmode='data',
1241
+ paper_bgcolor=backgroundColor,
1242
+ plot_bgcolor=backgroundColor,
1243
+ margin=dict(l=marginLeft, r=marginRight, t=marginTop, b=marginBottom),
1244
+ )
1245
+ figure.update_xaxes(showgrid=False, zeroline=False, visible=False)
1246
+ figure.update_yaxes(showgrid=False, zeroline=False, visible=False)
1247
+ return figure
1248
+
1249
+ @staticmethod
1250
+ def FigureByPieChart(data, values, names):
1251
+ """
1252
+ Creates a plotly pie chart figure.
1253
+
1254
+ Parameters
1255
+ ----------
1256
+ data : list
1257
+ The input list of plotly data.
1258
+ values : list
1259
+ The input list of values.
1260
+ names : list
1261
+ The input list of names.
1262
+ """
1263
+ import pandas as pd
1264
+ import plotly.express as px
1265
+ dlist = list(map(list, zip(*data)))
1266
+ df = pd.DataFrame(dlist, columns=data['names'])
1267
+ fig = px.pie(df, values=values, names=names)
1268
+ return fig
1269
+
1270
+ @staticmethod
1271
+ def SetCamera(figure, camera=[1.25, 1.25, 1.25], target=[0, 0, 0], up=[0, 0, 1]):
1272
+ """
1273
+ Sets the camera for the input figure.
1274
+
1275
+ Parameters
1276
+ ----------
1277
+ figure : plotly.graph_objs._figure.Figure
1278
+ The input plotly figure.
1279
+ camera : list , optional
1280
+ The desired location of the camera. The default is [0,0,0].
1281
+ target : list , optional
1282
+ The desired camera target. The default is [0,0,0].
1283
+ up : list , optional
1284
+ The desired up vector. The default is [0,0,1].
1285
+
1286
+ Returns
1287
+ -------
1288
+ plotly.graph_objs._figure.Figure
1289
+ The updated figure
1290
+
1291
+ """
1292
+ if not isinstance(camera, list):
1293
+ return None
1294
+ if not isinstance(target, list):
1295
+ return None
1296
+ if not isinstance(up, list):
1297
+ return None
1298
+ scene_camera = dict(
1299
+ up=dict(x=up[0], y=up[1], z=up[2]),
1300
+ eye=dict(x=camera[0], y=camera[1], z=camera[2]),
1301
+ center=dict(x=target[0], y=target[1], z=target[2])
1302
+ )
1303
+ figure.update_layout(scene_camera=scene_camera)
1304
+ return figure
1305
+
1306
+ @staticmethod
1307
+ def Show(figure, camera=[1.25, 1.25, 1.25], renderer="notebook", target=[0, 0, 0], up=[0, 0, 1]):
1308
+ """
1309
+ Shows the input figure.
1310
+
1311
+ Parameters
1312
+ ----------
1313
+ figure : plotly.graph_objs._figure.Figure
1314
+ The input plotly figure.
1315
+ camera : list , optional
1316
+ The desired location of the camera. The default is [0,0,0].
1317
+ renderer : str , optional
1318
+ The desired rendered. See Plotly.Renderers(). The default is "notebook".
1319
+ target : list , optional
1320
+ The desired camera target. The default is [0,0,0].
1321
+ up : list , optional
1322
+ The desired up vector. The default is [0,0,1].
1323
+
1324
+ Returns
1325
+ -------
1326
+ None
1327
+
1328
+ """
1329
+ if not isinstance(figure, plotly.graph_objs._figure.Figure):
1330
+ print("Not a figure, returning None")
1331
+ return None
1332
+ if not renderer.lower() in Plotly.Renderers():
1333
+ print("Not a valid renderer, returning None")
1334
+ return None
1335
+ figure = Plotly.SetCamera(figure, camera=camera, target=target, up=up)
1336
+ figure.show(renderer=renderer)
1337
+ return None
1338
+
1339
+ @staticmethod
1340
+ def Renderers():
1341
+ """
1342
+ Returns a list of the available plotly renderers.
1343
+
1344
+ Parameters
1345
+ ----------
1346
+
1347
+ Returns
1348
+ -------
1349
+ list
1350
+ The list of the available plotly renderers.
1351
+
1352
+ """
1353
+ return ['plotly_mimetype', 'jupyterlab', 'nteract', 'vscode',
1354
+ 'notebook', 'notebook_connected', 'kaggle', 'azure', 'colab',
1355
+ 'cocalc', 'databricks', 'json', 'png', 'jpeg', 'jpg', 'svg',
1356
+ 'pdf', 'browser', 'firefox', 'chrome', 'chromium', 'iframe',
1357
+ 'iframe_connected', 'sphinx_gallery', 'sphinx_gallery_png']
1358
+
1359
+ @staticmethod
1360
+ def ExportToImage(figure, path, format="png", width="1920", height="1080"):
1361
+ """
1362
+ Exports the plotly figure to an image.
1363
+
1364
+ Parameters
1365
+ ----------
1366
+ figure : plotly.graph_objs._figure.Figure
1367
+ The input plotly figure.
1368
+ path : str
1369
+ The image file path.
1370
+ format : str , optional
1371
+ The desired format. This can be any of "jpg", "jpeg", "pdf", "png", "svg", or "webp". It is case insensitive. The default is "png".
1372
+ width : int , optional
1373
+ The width in pixels of the figure. The default value is 1920.
1374
+ height : int , optional
1375
+ The height in pixels of the figure. The default value is 1080.
1376
+
1377
+ Returns
1378
+ -------
1379
+ bool
1380
+ True if the image was exported sucessfully. False otherwise.
1381
+
1382
+ """
1383
+ if not isinstance(figure, plotly.graph_objs._figure.Figure):
1384
+ return None
1385
+ if not isinstance(path, str):
1386
+ return None
1387
+ if not format.lower() in ["jpg", "jpeg", "pdf", "png", "svg", "webp"]:
1388
+ return None
1389
+ returnStatus = False
1390
+ try:
1391
+ plotly.io.write_image(figure, path, format=format.lower(), scale=None, width=width, height=height, validate=True, engine='auto')
1392
+ returnStatus = True
1393
+ except:
1394
+ returnStatus = False
1395
+ return returnStatus
1396
+