topologicpy 0.6.3__py3-none-any.whl → 0.7.0__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.
topologicpy/Plotly.py CHANGED
@@ -14,40 +14,11 @@
14
14
  # You should have received a copy of the GNU Affero General Public License along with
15
15
  # this program. If not, see <https://www.gnu.org/licenses/>.
16
16
 
17
- import topologicpy
18
17
  import topologic_core as topologic
19
18
 
20
- from topologicpy.Wire import Wire
21
- from topologicpy.Face import Face
22
19
  import os
23
20
  import warnings
24
21
 
25
- try:
26
- import numpy as np
27
- except:
28
- print("Plotly - Installing required numpy library.")
29
- try:
30
- os.system("pip install numpy")
31
- except:
32
- os.system("pip install numpy --user")
33
- try:
34
- import numpy as np
35
- except:
36
- warnings.warn("Plotly - Error: Could not import numpy.")
37
-
38
- try:
39
- import pandas as pd
40
- except:
41
- print("Plotly - Installing required pandas library.")
42
- try:
43
- os.system("pip install pandas")
44
- except:
45
- os.system("pip install pandas --user")
46
- try:
47
- import pandas as pd
48
- except:
49
- warnings.warn("Plotly - Error: Could not import pandas.")
50
-
51
22
  try:
52
23
  import plotly
53
24
  import plotly.graph_objects as go
@@ -93,6 +64,7 @@ class Plotly:
93
64
  The units used in the color bar. The default is ""
94
65
  colorScale : str , optional
95
66
  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/.
67
+ In addition to these, three color-blind friendly scales are included. These are "protanopia", "deuteranopia", and "tritanopia" for red, green, and blue colorblindness respectively.
96
68
  mantissa : int , optional
97
69
  The desired length of the mantissa for the values listed on the color bar. The default is 6.
98
70
  Returns
@@ -121,7 +93,7 @@ class Plotly:
121
93
  showlegend=False,
122
94
  marker=dict(
123
95
  size=0,
124
- colorscale=colorScale, # choose the colorscale
96
+ colorscale=Plotly.ColorScale(colorScale), # choose the colorscale
125
97
  cmin=minValue,
126
98
  cmax=maxValue,
127
99
  color=['rgba(0,0,0,0)'],
@@ -202,7 +174,58 @@ class Plotly:
202
174
  "violet","wheat","white",
203
175
  "whitesmoke","yellow","yellowgreen"]
204
176
 
205
-
177
+ @staticmethod
178
+ def ColorScale(colorScale: str = "viridis"):
179
+
180
+ # Colors recommended by various sources for color-blind-friendly palettes
181
+ protanopia_colors = [
182
+ "#E69F00", # orange
183
+ "#56B4E9", # sky blue
184
+ "#009E73", # bluish green
185
+ "#F0E442", # yellow
186
+ "#0072B2", # blue
187
+ "#D55E00", # vermillion
188
+ "#CC79A7", # reddish purple
189
+ ]
190
+
191
+ deuteranopia_colors = [
192
+ "#377EB8", # blue
193
+ "#FF7F00", # orange
194
+ "#4DAF4A", # green
195
+ "#F781BF", # pink
196
+ "#A65628", # brown
197
+ "#984EA3", # purple
198
+ "#999999", # grey
199
+ ]
200
+
201
+ tritanopia_colors = [
202
+ "#E69F00", # orange
203
+ "#56B4E9", # sky blue
204
+ "#009E73", # bluish green
205
+ "#F0E442", # yellow
206
+ "#0072B2", # blue
207
+ "#D55E00", # vermillion
208
+ "#CC79A7", # reddish purple
209
+ ]
210
+
211
+ # Create colorscales for Plotly
212
+ def create_colorscale(colors):
213
+ colorscale = []
214
+ num_colors = len(colors)
215
+ for i, color in enumerate(colors):
216
+ position = i / (num_colors - 1)
217
+ colorscale.append((position, color))
218
+ return colorscale
219
+
220
+ if "prota" in colorScale.lower():
221
+ return create_colorscale(protanopia_colors)
222
+ elif "deutera" in colorScale.lower():
223
+ return create_colorscale(deuteranopia_colors)
224
+ elif "trita"in colorScale.lower():
225
+ return create_colorscale(tritanopia_colors)
226
+ else:
227
+ return colorScale
228
+
206
229
  @staticmethod
207
230
  def DataByDGL(data, labels):
208
231
  """
@@ -222,6 +245,20 @@ class Plotly:
222
245
 
223
246
  """
224
247
 
248
+ try:
249
+ import pandas as pd
250
+ except:
251
+ print("Plotly - Installing required pandas library.")
252
+ try:
253
+ os.system("pip install pandas")
254
+ except:
255
+ os.system("pip install pandas --user")
256
+ try:
257
+ import pandas as pd
258
+ except:
259
+ warnings.warn("Plotly.DataByDGL - Error: Could not import pandas. Please install the pandas library manually. Returning None")
260
+ return None
261
+
225
262
  if isinstance(data[labels[0]][0], int):
226
263
  xAxis_list = list(range(1, data[labels[0]][0]+1))
227
264
  else:
@@ -241,7 +278,7 @@ class Plotly:
241
278
 
242
279
  Parameters
243
280
  ----------
244
- graph : topologic.Graph
281
+ graph : topologic_core.Graph
245
282
  The input graph.
246
283
  vertexColor : str , optional
247
284
  The desired color of the output vertices. This can be any plotly color string and may be specified as:
@@ -298,7 +335,7 @@ class Plotly:
298
335
  from topologicpy.Graph import Graph
299
336
  import plotly.graph_objs as go
300
337
 
301
- if not isinstance(graph, topologic.Graph):
338
+ if not Topology.IsInstance(graph, "Graph"):
302
339
  return None
303
340
  v_labels = []
304
341
  v_groupList = []
@@ -352,7 +389,7 @@ class Plotly:
352
389
  marker=dict(symbol='circle',
353
390
  size=vertexSize,
354
391
  color=v_groupList,
355
- colorscale=colorScale,
392
+ colorscale=Plotly.ColorScale(colorScale),
356
393
  line=dict(color=edgeColor, width=0.5)
357
394
  ),
358
395
  text=v_labels,
@@ -448,13 +485,13 @@ class Plotly:
448
485
  faceMinGroup=None, faceMaxGroup=None,
449
486
  showFaceLegend=False, faceLegendLabel="Topology Faces", faceLegendRank=3,
450
487
  faceLegendGroup=3,
451
- intensityKey=None, intensities=[], colorScale="Viridis", mantissa=6, tolerance=0.0001):
488
+ intensityKey=None, intensities=[], colorScale="viridis", mantissa=6, tolerance=0.0001):
452
489
  """
453
490
  Creates plotly face, edge, and vertex data.
454
491
 
455
492
  Parameters
456
493
  ----------
457
- topology : topologic.Topology
494
+ topology : topologic_core.Topology
458
495
  The input topology. This must contain faces and or edges.
459
496
 
460
497
  showVertices : bool , optional
@@ -737,7 +774,7 @@ class Plotly:
737
774
  def faceData(vertices, faces, dictionaries=None, color="#FAFAFA",
738
775
  opacity=0.5, labelKey=None, groupKey=None,
739
776
  minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Faces",
740
- legendGroup=3, legendRank=3, showLegend=True, intensities=None, colorScale="Viridis"):
777
+ legendGroup=3, legendRank=3, showLegend=True, intensities=None, colorScale="viridis"):
741
778
  x = []
742
779
  y = []
743
780
  z = []
@@ -820,7 +857,7 @@ class Plotly:
820
857
  legendrank = legendRank,
821
858
  color = color,
822
859
  facecolor = groupList,
823
- colorscale = colorScale,
860
+ colorscale = Plotly.ColorScale(colorScale),
824
861
  cmin = 0,
825
862
  cmax = 1,
826
863
  intensity = intensities,
@@ -834,11 +871,13 @@ class Plotly:
834
871
  )
835
872
  return fData
836
873
 
874
+ from topologicpy.Face import Face
837
875
  from topologicpy.Cluster import Cluster
838
876
  from topologicpy.Topology import Topology
839
877
  from topologicpy.Dictionary import Dictionary
840
878
  from time import time
841
- if not isinstance(topology, topologic.Topology):
879
+
880
+ if not Topology.IsInstance(topology, "Topology"):
842
881
  return None
843
882
 
844
883
  intensityList = []
@@ -846,7 +885,7 @@ class Plotly:
846
885
  data = []
847
886
  v_list = []
848
887
 
849
- if topology.Type() == topologic.Vertex.Type():
888
+ if Topology.Type(topology) == Topology.TypeID("Vertex"):
850
889
  tp_vertices = [topology]
851
890
  else:
852
891
  tp_vertices = Topology.Vertices(topology)
@@ -902,8 +941,8 @@ class Plotly:
902
941
  vertices.append([tp_v.X(), tp_v.Y(), tp_v.Z()])
903
942
  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))
904
943
 
905
- if showEdges and topology.Type() > topologic.Vertex.Type():
906
- if topology.Type() == topologic.Edge.Type():
944
+ if showEdges and Topology.Type(topology) > Topology.TypeID("Vertex"):
945
+ if Topology.Type(topology) == Topology.TypeID("Edge"):
907
946
  tp_edges = [topology]
908
947
  else:
909
948
  tp_edges = Topology.Edges(topology)
@@ -918,8 +957,8 @@ class Plotly:
918
957
  edges = geo['edges']
919
958
  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))
920
959
 
921
- if showFaces and topology.Type() >= topologic.Face.Type():
922
- if isinstance(topology, topologic.Face):
960
+ if showFaces and Topology.Type(topology) >= Topology.TypeID("Face"):
961
+ if Topology.IsInstance(topology, "Face"):
923
962
  tp_faces = [topology]
924
963
  else:
925
964
  tp_faces = Topology.Faces(topology)
@@ -934,7 +973,7 @@ class Plotly:
934
973
  #ibList = [Wire.RemoveCollinearEdges(ib) for ib in ibList]
935
974
  #ibList = [ib for ib in ibList if not ib == None]
936
975
  #new_f = Face.ByWires(eb, ibList, silent=False)
937
- #if isinstance(new_f, topologic.Face):
976
+ #if Topology.IsInstance(new_f, "Face"):
938
977
  #if faceLabelKey or faceGroupKey:
939
978
  #d = Topology.Dictionary(tp_faces[i])
940
979
  #keys = Dictionary.Keys(d)
@@ -973,7 +1012,7 @@ class Plotly:
973
1012
  width=950,
974
1013
  height=500,
975
1014
  showScale = True,
976
- colorScale='Viridis',
1015
+ colorScale='viridis',
977
1016
  colorSamples=10,
978
1017
  backgroundColor='rgba(0,0,0,0)',
979
1018
  marginLeft=0,
@@ -1027,6 +1066,20 @@ class Plotly:
1027
1066
  The desired bottom margin in pixels. The default is 0.
1028
1067
 
1029
1068
  """
1069
+ try:
1070
+ import numpy as np
1071
+ except:
1072
+ print("Plotly.FigureByConfusionMatrix - Installing required numpy library.")
1073
+ try:
1074
+ os.system("pip install numpy")
1075
+ except:
1076
+ os.system("pip install numpy --user")
1077
+ try:
1078
+ import numpy as np
1079
+ except:
1080
+ warnings.warn("Plotly.FigureByConfusionMatrix - Error: Could not import numpy. Please install numpy manually. Returning None.")
1081
+ return None
1082
+
1030
1083
  if not isinstance(matrix, list) and not isinstance(matrix, np.ndarray):
1031
1084
  print("Plotly.FigureByConfusionMatrix - Error: The input matrix is not of the correct type. Returning None.")
1032
1085
  return None
@@ -1040,7 +1093,7 @@ class Plotly:
1040
1093
  width=width,
1041
1094
  height=height,
1042
1095
  showScale=showScale,
1043
- colorScale=colorScale,
1096
+ colorScale=Plotly.ColorScale(colorScale),
1044
1097
  colorSamples=colorSamples,
1045
1098
  backgroundColor=backgroundColor,
1046
1099
  marginLeft=marginLeft,
@@ -1126,6 +1179,20 @@ class Plotly:
1126
1179
  import plotly.graph_objects as go
1127
1180
  import plotly.express as px
1128
1181
 
1182
+ try:
1183
+ import numpy as np
1184
+ except:
1185
+ print("Plotly.FigureByMatrix - Installing required numpy library.")
1186
+ try:
1187
+ os.system("pip install numpy")
1188
+ except:
1189
+ os.system("pip install numpy --user")
1190
+ try:
1191
+ import numpy as np
1192
+ except:
1193
+ warnings.warn("Plotly.FigureByMatrix - Error: Could not import numpy. Please install numpy manually. Returning None.")
1194
+ return None
1195
+
1129
1196
  if not isinstance(matrix, list) and not isinstance(matrix, np.ndarray):
1130
1197
  print("Plotly.FigureByMatrix - Error: The input matrix is not of the correct type. Returning None.")
1131
1198
  return None
@@ -1134,7 +1201,7 @@ class Plotly:
1134
1201
 
1135
1202
  if isinstance(matrix, list):
1136
1203
  matrix = np.array(matrix)
1137
- colors = px.colors.sample_colorscale(colorScale, [n/(colorSamples -1) for n in range(colorSamples)])
1204
+ colors = px.colors.sample_colorscale(Plotly.ColorScale(colorScale), [n/(colorSamples -1) for n in range(colorSamples)])
1138
1205
 
1139
1206
  if not xCategories:
1140
1207
  xCategories = [x for x in range(len(matrix[0]))]
@@ -1471,6 +1538,21 @@ class Plotly:
1471
1538
  """
1472
1539
 
1473
1540
  import plotly.express as px
1541
+
1542
+ try:
1543
+ import pandas as pd
1544
+ except:
1545
+ print("Plotly.FigureByPieChart - Installing required pandas library.")
1546
+ try:
1547
+ os.system("pip install pandas")
1548
+ except:
1549
+ os.system("pip install pandas --user")
1550
+ try:
1551
+ import pandas as pd
1552
+ except:
1553
+ warnings.warn("Plotly.FigureByPieChart - Error: Could not import pandas. Please install the pandas library manually. Returning None")
1554
+ return None
1555
+
1474
1556
  dlist = list(map(list, zip(*data)))
1475
1557
  df = pd.DataFrame(dlist, columns=data['names'])
1476
1558
  fig = px.pie(df, values=values, names=names)
@@ -1502,13 +1584,13 @@ class Plotly:
1502
1584
  marginLeft=0, marginRight=0, marginTop=20, marginBottom=0, showScale=False,
1503
1585
 
1504
1586
  cbValues=[], cbTicks=5, cbX=-0.15, cbWidth=15, cbOutlineWidth=0, cbTitle="",
1505
- cbSubTitle="", cbUnits="", colorScale="Viridis", mantissa=6, tolerance=0.0001):
1587
+ cbSubTitle="", cbUnits="", colorScale="viridis", mantissa=6, tolerance=0.0001):
1506
1588
  """
1507
1589
  Creates a figure from the input topology.
1508
1590
 
1509
1591
  Parameters
1510
1592
  ----------
1511
- topology : topologic.Topology
1593
+ topology : topologic_core.Topology
1512
1594
  The input topology. This must contain faces and or edges.
1513
1595
 
1514
1596
  showVertices : bool , optional
@@ -1669,7 +1751,9 @@ class Plotly:
1669
1751
  Plotly figure
1670
1752
 
1671
1753
  """
1672
- if not isinstance(topology, topologic.Topology):
1754
+ from topologicpy.Topology import Topology
1755
+
1756
+ if not Topology.IsInstance(topology, "Topology"):
1673
1757
  print("Plotly.FigureByTopology - Error: the input topology is not a valid topology. Returning None.")
1674
1758
  return None
1675
1759
  data = Plotly.DataByTopology(topology=topology,