Commit 4fc893b4 authored by Philippe SWARTVAGHER's avatar Philippe SWARTVAGHER
Browse files

CommCompGraph: support interleaving build of several CommCompGraph before saving them

Not sure if it works correctly for the show() method.
parent 57fc36e1
......@@ -726,6 +726,7 @@ class CommCompGraph:
"cursor": "Arithmetic Intensity (FLOP/B)\n← Memory-bound ⇹ CPU-bound →"
}
_FILL_ALPHA = 0.3
_nb_instances = 1 # to interleave generation of several plots, plt.figure indexing starts with 1
def __init__(self, x_range, x_type: str, comm_type: CommCompGraphCommType, comp_type: CompType, comp_metric: CompMetric, comm_legend_title=None, comp_legend_title=None, title=None, legend_fontsize="medium", x_span_zone=None):
if x_type not in self._X_LABELS:
......@@ -759,8 +760,12 @@ class CommCompGraph:
self.title = title
self._left_y_max = 0
self._right_y_max = 0
self._instance_id = CommCompGraph._nb_instances
self._fig, self._ax = plt.subplots()
CommCompGraph._nb_instances += 1
self._fig = plt.figure(self._instance_id)
self._ax = self._fig.gca()
self._ax.grid()
self._ax.set_xlabel(self._X_LABELS[self._x_type])
......@@ -818,6 +823,8 @@ class CommCompGraph:
self._ax.axvline(x, **kwargs)
def _plot(self):
plt.figure(self._instance_id)
shrink_plot_legend = { # dict to tell how much to shrink the plot according to the number of legend rows:
1: 0.8,
2: 0.8,
......@@ -918,12 +925,14 @@ class CommCompGraph:
self._plotted = True
def show(self):
plt.figure(self._instance_id)
if not self._plotted:
self._plot()
plt.show()
def save(self, filename):
plt.figure(self._instance_id)
if not self._plotted:
self._plot()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment