You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might not be a bug but I doubt that it is an intended behavior. figure.clf() don't change the subplot parameters to any default values so it is not enough to do figure.clf() when testing to plot with or without for example tight_layout . This is easy to fix by adding for example:
keys = ('left', 'right', 'bottom','top','wspace','hspace')
subplots_default = {key : rcParams['figure.subplot.' + key] for key in keys}
self.subplotpars.update(**subplots_default)
to figure.clf()
When I looked into this I also found that the docstrings for subplots_adjust and SubplotParams are kind of confusing and not really correct. The default is, except in SuplotParams.__ini__ (that most people probably newer use directly), not the rc parameters that it seems but the actual attributes in the SuplotParams object. So it is not trivial to start all over with the default rc variables after a change in the subplotparameters by for example tight_layout.
Would it be good to add an option in subplot_adjust to adjust to the default parameters?
Would it be good to add a get function for the subplotparameters?
The documentation should probably be changed anyway. Are there any method to avoid writing almost the same things several times? figure.subplots_adjust and plt.subplots_adjust should have more or less the exact same docstring and the SuplotParams should also have a similar one.
I'm not sure if this is intended behaviour or not. If understand what you are describing, it seems like clf should indeed reset those values. Not sure about the utility of getters and setters etc.
There is a tension in the docs between reproducibility and simplicity. See the legend doc (in Master) for one way to make the docstrings consistent.
...probably not the recommended way.
Similarly you may get all subplot parameters by just using the SuplotParams' __dict__
print(fig.subplotpars.__dict__)
So given that those are really suboptimal "solutions", I think it would be good to
introduce a reset_to_rc function into SubplotParams.
let clf call this function.
introduce either a figure method fig.get_subplotparams() or a subplot param method fig.subplotparams.get_params() returning a dictionary of the 6 subplotparams.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
The first and most important thing to do here is define what "clear" means for a figure. To do that, we should identify the use case ("Why clear and reuse a figure instead of just creating a new one?"). I see the main application when the figure is embedded in an application and you want to update the plot. Therefore:
clear() should (and currently does) remove:
all content (subfigs, Axes, Legends, suptitle etc.)
clear() should (and currently does) keep:
all "wiring", canvas, toolbar, embedding in parent figs (for subfigs), etc.
figure size, dpi
I'm undecided on (and believe they are currently not reset):
patch properties (facecolor, frame, ...)
layout engine
subplotpars
Whether they should be reset or not depends on how similar / different the new plot is. One can argue that these are similar fundamental visual properties like figure size and thus should not be reset. OTOH if the new should look substantially different, it's cumbersome to reset these manually.
Activity
[-]fig.clf() and subplots_adjust[/-][+]figure.clf() and subplots_adjust[/+]jklymak commentedon Apr 16, 2018
I'm not sure if this is intended behaviour or not. If understand what you are describing, it seems like
clfshould indeed reset those values. Not sure about the utility of getters and setters etc.There is a tension in the docs between reproducibility and simplicity. See the
legenddoc (in Master) for one way to make the docstrings consistent.ImportanceOfBeingErnest commentedon Apr 16, 2018
A crazy way to reset the subplotpars to the rcParams' values would be
...probably not the recommended way.
Similarly you may get all subplot parameters by just using the
SuplotParams'__dict__So given that those are really suboptimal "solutions", I think it would be good to
reset_to_rcfunction intoSubplotParams.clfcall this function.fig.get_subplotparams()or a subplot param methodfig.subplotparams.get_params()returning a dictionary of the 6 subplotparams.efiring commentedon Jul 2, 2018
I added two labels because
github-actions commentedon Sep 9, 2024
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
timhoffm commentedon Sep 9, 2024
The first and most important thing to do here is define what "clear" means for a figure. To do that, we should identify the use case ("Why clear and reuse a figure instead of just creating a new one?"). I see the main application when the figure is embedded in an application and you want to update the plot. Therefore:
clear()should (and currently does) remove:clear()should (and currently does) keep:I'm undecided on (and believe they are currently not reset):
Whether they should be reset or not depends on how similar / different the new plot is. One can argue that these are similar fundamental visual properties like figure size and thus should not be reset. OTOH if the new should look substantially different, it's cumbersome to reset these manually.