Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

StephenNneji
Copy link
Contributor

Adds a class to facilitate a blit plot in RasCAL, this class can be tested as shown below. The object creation should do a normal plot then subsequent updates will use blitting if the background has not changed. This leads to a decent speed up between the first draw and subsequent draws.

 class TestPlot:
    def __init__(self, block=False):
        self.block = block
        self.closed = False
        self.blit_plot = None

    def __enter__(self):
        self.figure = plt.subplots(1, 2)[0]
        self.figure.canvas.mpl_connect("close_event", self._setCloseState)
        self.figure.show()
        RATapi.events.register(RATapi.events.EventTypes.Plot, self.plotEvent)

        return self.figure

    def _setCloseState(self, _):
        self.closed = True

    def plotEvent(self, event):
        if not self.closed and self.figure.number in plt.get_fignums():
            if self.blit_plot is None:
                self.blit_plot = PLotSLDWithBlitting(event, self.figure)
            else:
                self.blit_plot.update(event)

    def __exit__(self, _exc_type, _exc_val, _traceback):
        RATapi.events.clear(RATapi.events.EventTypes.Plot, self.plotEvent)
        if not self.closed and self.figure.number in plt.get_fignums():
            plt.show(block=self.block)

Usage will be

with TestPlot(block=True):
    problem, results = DSPC_standard_layers()

@StephenNneji StephenNneji requested a review from DrPaulSharp May 8, 2025 09:25
Copy link
Collaborator

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good, and some good speedup. Just a few (hopefully) straightforward things to look at.

@StephenNneji StephenNneji merged commit 051b4ba into RascalSoftware:main May 9, 2025
7 checks passed
@StephenNneji StephenNneji deleted the blitting branch September 3, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants