source: cpp/frams/_demos/geneprops_graph.py @ 1313

Last change on this file since 1313 was 1302, checked in by Maciej Komosinski, 7 months ago

Cosmetic / minor fixes

File size: 1.8 KB
Line 
1# This file is a part of Framsticks SDK.  http://www.framsticks.com/
2# Copyright (C) 2023  Maciej Komosinski and Szymon Ulatowski.
3# See LICENSE.txt for details.
4
5import matplotlib.pyplot as plt
6from matplotlib.collections import LineCollection
7import sys
8import csv
9
10# Visualizing the influence of Framsticks f1/f4 modifier sequences. See also geneprops_test.cpp
11# usage:
12# ./geneprops_test f 3 -e | python3 frams/_demos/geneprops_graph.py
13#
14# See also https://colab.research.google.com/drive/1x9FTAUQKFhvxX_IyEcglWRWa4ylZeY-7?usp=sharing
15
16#################################################
17# loading
18
19nodes_list = [] # ['modifiers', value]
20
21for line in csv.reader(sys.stdin.readlines(),delimiter='\t'):
22    if line[0]=='-':
23        line[0]=''
24    nodes_list.append([line[0],float(line[1])])
25
26nodes_dict = {} # ['modifiers', value, [children,...]]
27   
28for n in sorted(nodes_list, key=lambda e: len(e[0])):
29    tree_node = [n[0],n[1],[]]
30    if n[0]!='':
31        nodes_dict[n[0][:-1]][2].append(tree_node)
32    nodes_dict[n[0]] = tree_node
33   
34#################################################
35# plotting
36
37fig, ax = plt.subplots(figsize=(4, 4))
38ax.set(title="Tree of modifier values")
39
40segs=[]
41for n in nodes_dict.values():
42    for child in n[2]:
43        segs.append( ((len(n[0]),n[1]),(len(n[0])+1,child[1])) )
44
45linecol = LineCollection(segs, linewidths=2, linestyle='solid', color='#ddddff')
46ax.add_collection(linecol)
47
48node_x = [len(n[0]) for n in nodes_dict.values()]
49node_y = [n[1] for n in nodes_dict.values()]
50
51ax.plot(node_x, node_y, "o", color="w", markerfacecolor="r")
52
53for n in nodes_dict.values():
54    ax.annotate(n[0], (len(n[0]),n[1]), textcoords="offset points", horizontalalignment="right", verticalalignment='center', xytext=(-4,0))
55
56ax.xaxis.set_visible(False)
57plt.tight_layout()
58plt.show()
Note: See TracBrowser for help on using the repository browser.