Skip to content
Snippets Groups Projects
schedule.py 38.8 KiB
Newer Older
  • Learn to ignore specific revisions
  • Oscar Gustafsson's avatar
    Oscar Gustafsson committed
        def _reset_y_locations(self) -> None:
    
            """Reset all the y-locations in the schedule to None"""
    
            self._y_locations = defaultdict(_y_locations_default)
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
        def plot(self, ax: Axes, operation_gap: Optional[float] = None) -> 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.
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            self._plot_schedule(ax, operation_gap=operation_gap)
    
        def show(
            self, operation_gap: Optional[float] = None, title: Optional[str] = None
        ) -> None:
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            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.
    
            title : str, optional
                Figure title.
    
            fig = self._get_figure(operation_gap=operation_gap)
            if title:
                fig.suptitle(title)
            fig.show()
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
        def _get_figure(self, operation_gap: Optional[float] = None) -> 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.
    
            The Matplotlib Figure.
    
            fig, ax = plt.subplots()
    
            self._plot_schedule(ax, operation_gap=operation_gap)
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            return fig
    
        def _repr_svg_(self) -> str:
    
            Generate an SVG of the schedule. This is automatically displayed in e.g.
            Jupyter Qt console.
    
            fig, ax = plt.subplots()
            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_