Spaces:
Running
Running
neuralworm
commited on
Commit
•
8e31850
1
Parent(s):
42a21e8
plotly instead of matplotlib
Browse files- psychohistory.py +13 -3
psychohistory.py
CHANGED
@@ -124,21 +124,31 @@ def draw_graph_plotly(G, title="3D Event Tree", highlight_color='gray'):
|
|
124 |
html_str = fig.to_html(full_html=False, include_plotlyjs='cdn')
|
125 |
return html_str
|
126 |
|
|
|
127 |
def main(json_data):
|
128 |
G = nx.DiGraph()
|
129 |
build_graph_from_json(json_data, G)
|
130 |
|
|
|
|
|
|
|
131 |
# Generate the HTML string for the Plotly graph
|
132 |
html_graph = draw_graph_plotly(G)
|
133 |
|
134 |
-
#
|
135 |
-
|
136 |
if best_path:
|
137 |
best_path_graph = draw_graph_plotly(G.subgraph(best_path), title="Best Path", highlight_color='blue')
|
138 |
html_graph += best_path_graph
|
139 |
if worst_path:
|
140 |
worst_path_graph = draw_graph_plotly(G.subgraph(worst_path), title="Worst Path", highlight_color='red')
|
141 |
html_graph += worst_path_graph
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
return html_graph # Return the HTML string
|
|
|
|
|
|
124 |
html_str = fig.to_html(full_html=False, include_plotlyjs='cdn')
|
125 |
return html_str
|
126 |
|
127 |
+
|
128 |
def main(json_data):
|
129 |
G = nx.DiGraph()
|
130 |
build_graph_from_json(json_data, G)
|
131 |
|
132 |
+
# Find the best, worst, longest, and shortest paths FIRST
|
133 |
+
best_path, best_mean_prob, worst_path, worst_mean_prob, longest_path, shortest_path = find_paths(G)
|
134 |
+
|
135 |
# Generate the HTML string for the Plotly graph
|
136 |
html_graph = draw_graph_plotly(G)
|
137 |
|
138 |
+
# Now you can use the path variables
|
|
|
139 |
if best_path:
|
140 |
best_path_graph = draw_graph_plotly(G.subgraph(best_path), title="Best Path", highlight_color='blue')
|
141 |
html_graph += best_path_graph
|
142 |
if worst_path:
|
143 |
worst_path_graph = draw_graph_plotly(G.subgraph(worst_path), title="Worst Path", highlight_color='red')
|
144 |
html_graph += worst_path_graph
|
145 |
+
if longest_path:
|
146 |
+
longest_path_graph = draw_graph_plotly(G.subgraph(longest_path), title="Longest Path", highlight_color='green')
|
147 |
+
html_graph += longest_path_graph
|
148 |
+
if shortest_path:
|
149 |
+
shortest_path_graph = draw_graph_plotly(G.subgraph(shortest_path), title="Shortest Path", highlight_color='purple')
|
150 |
+
html_graph += shortest_path_graph
|
151 |
|
152 |
return html_graph # Return the HTML string
|
153 |
+
|
154 |
+
|