Newer
Older
ax.add_patch(Polygon(xy.T, fc=_LATENCY_COLOR))
if 'in' in str(graph_id):
ax.annotate(
graph_id,
xy=(op_start_time - 0.48, y_pos + 0.7),
color="black",
size=10 - (0.05 * len(self._start_times)),
)
else:
ax.annotate(
graph_id,
xy=(op_start_time + 0.03, y_pos + 0.7),
color="black",
size=10 - (0.05 * len(self._start_times)),
)
if execution_time_coordinates:
_x, _y = zip(*execution_time_coordinates)
x = np.array(_x)
y = np.array(_y)
color=_EXECUTION_TIME_COLOR,
ytickpositions.append(y_pos + 0.5)
yticklabels.append(cast(Operation, self._sfg.find_by_id(graph_id)).name)
for graph_id, op_start_time in self._start_times.items():
operation = cast(Operation, self._sfg.find_by_id(graph_id))
out_coordinates = operation.get_output_coordinates()
source_y_pos = self._get_y_position(graph_id, operation_gap=operation_gap)
for output_port in operation.outputs:
for output_signal in output_port.signals:
destination = cast(InputPort, output_signal.destination)
destination_op = destination.operation
destination_start_time = self._start_times[destination_op.graph_id]
destination_y_pos = self._get_y_position(
destination_op.graph_id, operation_gap=operation_gap
destination_in_coordinates = (
out_coordinates[output_port.index],
[op_start_time, source_y_pos],
[destination_start_time, destination_y_pos],
name=graph_id,
ax.set_yticks(ytickpositions)
ax.set_yticklabels(yticklabels)
# Get operation with maximum position
max_pos_graph_id = max(self._y_locations, key=self._y_locations.get)
self._get_y_position(max_pos_graph_id, operation_gap=operation_gap)
+ 1
+ (OPERATION_GAP if operation_gap is None else operation_gap)
)
ax.axis([-1, self._schedule_time + 1, y_position_max, 0]) # Inverted y-axis
ax.xaxis.set_major_locator(MaxNLocator(integer=True, min_n_ticks=1))
ax.axvline(
0,
linestyle="--",
color="black",
ax.axvline(
self._schedule_time,
linestyle="--",
color="black",
"""Reset all the y-locations in the schedule to None"""
self._y_locations = defaultdict(_y_locations_default)
def plot(self, ax: Axes, operation_gap: float = OPERATION_GAP) -> None:
"""
Plot the schedule in a :class:`matplotlib.axes.Axes` or subclass.
Parameters
----------
ax : :class:`~matplotlib.axes.Axes`
The :class:`matplotlib.axes.Axes` to plot in.
operation_gap : float, optional
The vertical distance between operations in the schedule. The height of
the operation is always 1.
self, operation_gap: float = OPERATION_GAP, title: Optional[str] = None
Show the schedule. Will display based on the current Matplotlib backend.
Parameters
----------
operation_gap : float, optional
The vertical distance between operations in the schedule. The height of
the operation is always 1.
fig = self._get_figure(operation_gap=operation_gap)
if title:
fig.suptitle(title)
fig.show()
def _get_figure(self, operation_gap: float = OPERATION_GAP) -> Figure:
"""
Create a Figure and an Axes and plot schedule in the Axes.
Parameters
----------
operation_gap : float, optional
The vertical distance between operations in the schedule. The height of
the operation is always 1.
height = len(self._start_times) * 0.3 + 2
fig, ax = plt.subplots(figsize=(12, height))
self._plot_schedule(ax, operation_gap=operation_gap)
Generate an SVG of the schedule. This is automatically displayed in e.g.
Jupyter Qt console.
height = len(self._start_times) * 0.3 + 2
fig, ax = plt.subplots(figsize=(12, height))
self._plot_schedule(ax)
buffer = io.StringIO()
fig.savefig(buffer, format="svg")
return buffer.getvalue()
# SVG is valid HTML. This is useful for e.g. sphinx-gallery
_repr_html_ = _repr_svg_