-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix mplot3d projection #8896
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
Fix mplot3d projection #8896
Changes from 1 commit
64f197b
c765493
58e961d
c95fea3
c641607
7f1732e
e601965
0848bd1
0492b88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Fixes gh-8894, by always using a "position" that maintains a uniform coordinate system. Test added - when viewed from above, the plot should be square not rhombic.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``Axes3D`` now preserves right angles when rotating | ||
--------------------------------------------------- | ||
|
||
:class:`~mpl_toolkits.mplot3d.Axes3D` no longer stretches the plot in the x | ||
axis after projecting. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,6 +265,20 @@ def tunit_edges(self, vals=None, M=None): | |
(tc[7], tc[4])] | ||
return edges | ||
|
||
def apply_aspect(self, position=None): | ||
if position is None: | ||
position = self.get_position(original=True) | ||
|
||
# in the superclass, we would go through and actually deal with axis | ||
# scales and box/datalim. Those are all irrelevant - all we need to do | ||
# is make sure our coordinate system is square. | ||
figW, figH = self.get_figure().get_size_inches() | ||
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. Why use the figure's aspect ratio? What if the figure has 3 subplots all in a row? 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. Because all sizes in matplotlib are relative to the figure. Note that this is the same as the normal aspect=equal code, so is presumably correct. 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. Ping @efiring, as I think you are the resident expert on all the ways this could possibly go wrong. 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. I think it makes sense. I have no intention of spending the time required to understand mplot3d well enough to make a detailed review, but in the absence of any such review I am inclined to trust that this PR is a major improvement, as it appears to be fixing a basic design flaw. |
||
fig_aspect = figH / figW | ||
box_aspect = 1 | ||
pb = position.frozen() | ||
pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect) | ||
self.set_position(pb1.anchored(self.get_anchor(), pb), 'active') | ||
|
||
@artist.allow_rasterization | ||
def draw(self, renderer): | ||
# draw the background patch | ||
|
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.
This is a bit misleading. It isn't always a stretch in the x axis. Look at some of the image diffs, particularly the bar3d rotated one, and sometimes the stretching was in other directions. This is also misleading to some users because they may not be explicitly rotating the figure, but this still impacts them. This impacts just about anybody who has used mplot3d.
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.
It's a stretch in the window x axis (ie, the axis used after projection). You're right though, the wording is bad.