-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add Artist._cm_set for temporarily setting an Artist property. #19369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This corresponds to _setattr_cm, but for Artist properties. (Calling it `_set_cm` sounded too much like setting a "cm" property. Perhaps `_setattr_cm` should have been `_cm_setattr`...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: Alternatives could be _temporary_set
or _temp_properties
or similar.
with cbook._setattr_cm(self, manager=None), \ | ||
cbook._setattr_cm(self.figure, dpi=dpi), \ | ||
cbook._setattr_cm(canvas, _is_saving=True): | ||
origfacecolor = self.figure.get_facecolor() | ||
origedgecolor = self.figure.get_edgecolor() | ||
|
||
if facecolor is None: | ||
facecolor = rcParams['savefig.facecolor'] | ||
if cbook._str_equal(facecolor, 'auto'): | ||
facecolor = origfacecolor | ||
if edgecolor is None: | ||
edgecolor = rcParams['savefig.edgecolor'] | ||
if cbook._str_equal(edgecolor, 'auto'): | ||
edgecolor = origedgecolor | ||
|
||
self.figure.set_facecolor(facecolor) | ||
self.figure.set_edgecolor(edgecolor) | ||
cbook._setattr_cm(self.figure, dpi=dpi), \ | ||
cbook._setattr_cm(canvas, _is_saving=True), \ | ||
ExitStack() as stack: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could re-arrange this to avoid the escaped newlines:
with cbook._setattr_cm(self, manager=None), \ | |
cbook._setattr_cm(self.figure, dpi=dpi), \ | |
cbook._setattr_cm(canvas, _is_saving=True): | |
origfacecolor = self.figure.get_facecolor() | |
origedgecolor = self.figure.get_edgecolor() | |
if facecolor is None: | |
facecolor = rcParams['savefig.facecolor'] | |
if cbook._str_equal(facecolor, 'auto'): | |
facecolor = origfacecolor | |
if edgecolor is None: | |
edgecolor = rcParams['savefig.edgecolor'] | |
if cbook._str_equal(edgecolor, 'auto'): | |
edgecolor = origedgecolor | |
self.figure.set_facecolor(facecolor) | |
self.figure.set_edgecolor(edgecolor) | |
cbook._setattr_cm(self.figure, dpi=dpi), \ | |
cbook._setattr_cm(canvas, _is_saving=True), \ | |
ExitStack() as stack: | |
with ExitStack() as stack: | |
stack.enter_context(cbook._setattr_cm(self, manager=None)) | |
stack.enter_context(cbook._setattr_cm(self.figure, dpi=dpi)) | |
stack.enter_context(cbook._setattr_cm(canvas, _is_saving=True)) |
and maybe move the comment in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having syntactic context managers remains more readable; also note that in Py3.10+ we'll be able to parenthesize the multiple contextmanagers to avoid the backslashes anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
This corresponds to _setattr_cm, but for Artist properties.
(Calling it
_set_cm
sounded too much like setting a "cm" property.Perhaps
_setattr_cm
should have been_cm_setattr
...)See #19342 (comment) and discussion above.
PR Summary
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).