-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Remove 3D attributes from renderer #18302
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e47c19
Don't read 3D properties off the renderer for drawing.
QuLogic ab7e966
Remove unused function from art3d.
QuLogic 45777e4
Deprecate 3D properties on the renderer during draw.
QuLogic ed2b16a
Deprecate renderer parameter in do_3d_projection.
QuLogic a769837
Add some more explanatory comments to deprecations.
QuLogic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
3D properties on renderers | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The properties of the 3D Axes that were placed on the Renderer during draw are | ||
now deprecated: | ||
|
||
* ``renderer.M`` | ||
* ``renderer.eye`` | ||
* ``renderer.vvec`` | ||
* ``renderer.get_axis_position`` | ||
|
||
These attributes are all available via `.Axes3D`, which can be accessed via | ||
``self.axes`` on all `.Artist`\s. | ||
|
||
``renderer`` argument of ``do_3d_projection`` method for ``Collection3D``/``Patch3D`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The ``renderer`` argument for the ``do_3d_projection`` method on | ||
``Collection3D`` and ``Patch3D`` is no longer necessary, and passing it during | ||
draw is deprecated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -399,36 +399,71 @@ def draw(self, renderer): | |
|
||
# add the projection matrix to the renderer | ||
self.M = self.get_proj() | ||
renderer.M = self.M | ||
renderer.vvec = self.vvec | ||
renderer.eye = self.eye | ||
renderer.get_axis_position = self.get_axis_position | ||
QuLogic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Calculate projection of collections and patches and zorder them. | ||
# Make sure they are drawn above the grids. | ||
zorder_offset = max(axis.get_zorder() | ||
for axis in self._get_axis_list()) + 1 | ||
for i, col in enumerate( | ||
sorted(self.collections, | ||
key=lambda col: col.do_3d_projection(renderer), | ||
reverse=True)): | ||
col.zorder = zorder_offset + i | ||
for i, patch in enumerate( | ||
sorted(self.patches, | ||
key=lambda patch: patch.do_3d_projection(renderer), | ||
reverse=True)): | ||
patch.zorder = zorder_offset + i | ||
|
||
if self._axis3don: | ||
# Draw panes first | ||
for axis in self._get_axis_list(): | ||
axis.draw_pane(renderer) | ||
# Then axes | ||
for axis in self._get_axis_list(): | ||
axis.draw(renderer) | ||
props3d = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a note which of the following code can be removed once the deprecation expires. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically all of it... Updated the comment. |
||
# To raise a deprecation, we need to wrap the attribute in a | ||
# function, but binding that to an instance does not work, as you | ||
# would end up with an instance-specific method. Properties are | ||
# class-level attributes which *are* functions, so we do that | ||
# instead. | ||
# This dictionary comprehension creates deprecated properties for | ||
# the attributes listed below, and they are temporarily attached to | ||
# the _class_ in the `_setattr_cm` call. These can both be removed | ||
# once the deprecation expires | ||
name: cbook.deprecated('3.4', name=name, | ||
alternative=f'self.axes.{name}')( | ||
property(lambda self, _value=getattr(self, name): _value)) | ||
WeatherGod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for name in ['M', 'vvec', 'eye', 'get_axis_position'] | ||
} | ||
|
||
# Then rest | ||
super().draw(renderer) | ||
with cbook._setattr_cm(type(renderer), **props3d): | ||
def do_3d_projection(artist): | ||
""" | ||
Call `do_3d_projection` on an *artist*, and warn if passing | ||
*renderer*. | ||
|
||
For our Artists, never pass *renderer*. For external Artists, | ||
in lieu of more complicated signature parsing, always pass | ||
*renderer* and raise a warning. | ||
""" | ||
|
||
if artist.__module__ == 'mpl_toolkits.mplot3d.art3d': | ||
# Our 3D Artists have deprecated the renderer parameter, so | ||
# avoid passing it to them; call this directly once the | ||
# deprecation has expired. | ||
return artist.do_3d_projection() | ||
WeatherGod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cbook.warn_deprecated( | ||
"3.4", | ||
message="The 'renderer' parameter of " | ||
"do_3d_projection() was deprecated in Matplotlib " | ||
"%(since)s and will be removed %(removal)s.") | ||
return artist.do_3d_projection(renderer) | ||
|
||
# Calculate projection of collections and patches and zorder them. | ||
# Make sure they are drawn above the grids. | ||
zorder_offset = max(axis.get_zorder() | ||
for axis in self._get_axis_list()) + 1 | ||
for i, col in enumerate( | ||
sorted(self.collections, | ||
key=do_3d_projection, | ||
reverse=True)): | ||
col.zorder = zorder_offset + i | ||
for i, patch in enumerate( | ||
sorted(self.patches, | ||
key=do_3d_projection, | ||
reverse=True)): | ||
patch.zorder = zorder_offset + i | ||
|
||
if self._axis3don: | ||
# Draw panes first | ||
for axis in self._get_axis_list(): | ||
axis.draw_pane(renderer) | ||
# Then axes | ||
for axis in self._get_axis_list(): | ||
axis.draw(renderer) | ||
|
||
# Then rest | ||
super().draw(renderer) | ||
|
||
def get_axis_position(self): | ||
vals = self.get_w_lims() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.