POC + WIP: Track current PyGMT figure to avoid calling the figure
module repeatly
#3397
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
In all
Figure
methods, theSession._preprocess
method (or theSession._activate_figure
method) is called before we call the actual plotting method. TheSession._activate_figure
method activates the figure of the currentFigure
object so that any subsequent plotting commands write to this figure. Calling the method is necessary when we have multipleFigure
instances created and use them in a unfixed order. For example, it's necessary in the following case:However, in cases where we only have one
Figure
instance or newFigure
instance is created after we have finished the previous figure, callingSession._activate_figure
is not needed. For example:Thus, it would be good if we can only calling
Session._activate_figure
when necessary. This can be done by having a global PyGMT state variable that tracks the current activated figure. This PR serves as a proof of concept and it shows some performance improvements.The PyGMT state variable was initially proposed in #2388.