Skip to content
Snippets Groups Projects
Commit fb92e1fe authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Improved display

parent 9a0cfbf2
No related branches found
No related tags found
No related merge requests found
import matplotlib
import matplotlib.pyplot as plt
from functools import partial
import aidge_core
......@@ -54,20 +55,46 @@ class StaticAnalysisExt(aidge_core.StaticAnalysis):
continue
stats = self.get_op_stats(node)
series.append([namePtrTable[node], partial(callback, stats)()])
name = namePtrTable[node]
attr = {}
if type(node.get_operator()) is aidge_core.GenericOperatorOp:
# Display Generic Op in orange
attr = {'color': 'orange'}
elif not node.get_operator().is_atomic():
# Display Meta Op in bold
attr = {'fontweight': 'bold'}
elif node.type() not in aidge_core.get_keys_OperatorStats():
# Display unsupported operator in red labels
attr = {'color': 'red'}
if attr:
name = (name, attr)
series.append([name, partial(callback, stats)()])
if title is None: title = str(callback)
self._log_bar(series, filename, title, log_scale)
def _log_bar(self, series, filename, title=None, log_scale=False):
names, values = zip(*series)
names_only = [item[0] if isinstance(item, tuple) else item for item in names]
fig, ax = plt.subplots(figsize=(max(5, len(names)/4), 5))
plt.xlim(-0.5, len(names) - 0.5)
plt.bar(names, values)
plt.bar(names_only, values)
ax.yaxis.minorticks_on()
plt.grid(axis='y', which='major', linestyle='--', color='gray')
plt.grid(axis='y', which='minor', linestyle=':', color='lightgray')
formatter0 = matplotlib.ticker.EngFormatter(unit='')
ax.yaxis.set_major_formatter(formatter0)
plt.gca().set_axisbelow(True)
labels = plt.gca().get_xticks()
tick_labels = plt.gca().get_xticklabels()
for i, label in enumerate(labels):
if isinstance(names[i], tuple):
if 'color' in names[i][1]:
tick_labels[i].set_color(names[i][1]['color'])
elif 'fontweight' in names[i][1]:
tick_labels[i].set_fontweight(names[i][1]['fontweight'])
plt.xticks(rotation='vertical')
if log_scale: plt.yscale('log')
if title is not None: plt.title(title)
......
......@@ -63,6 +63,7 @@ void init_Operator(py::module& m){
.def_property_readonly("attr", &Operator::attributes)
.def("set_back_edges", &Operator::setBackEdges, py::arg("input_indexes"))
.def("is_back_edge", &Operator::isBackEdge, py::arg("input_index"))
.def("is_atomic", &Operator::isAtomic)
;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment