-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Jupyter "inline" backend seems to misinterpret "figsize" with Axes3D #16463
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
Comments
inline use
I'm going to close this as its understood behaviour and not a bug per-se, though I agree the decision to use |
Thanks for the quick answer @jklymak!
I was still surprised that the aspect ratio of the figure was completely changed. I would understand if some empty space were removed from all sides, but in this case a lot of "empty" space was removed from the left and right sides, but apparently not from the top and bottom? Are you sure that's not a bug in the Here are a few updated screenshots. First, for comparison, two cases repeated from above: And now without the And here's how "normal" 2D plots look without the |
I can't remember, but it might be that the tick labels for an Axes3D object
is stored in a separate location special for Axes3D. Therefore, the "tight"
algorithm doesn't know to check for those tick label's boxes.
…On Mon, Feb 10, 2020 at 3:22 PM Matthias Geier ***@***.***> wrote:
Thanks for the quick answer @jklymak <https://github.com/jklymak>!
I was actually already aware of the bbox_inches='tight' problem (I've
even mentioned it in my pamphlet about wrong default values in the inline
backend
<https://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/plotting/matplotlib-inline-defaults.ipynb>),
but I didn't realize that it was also the culprit in this case!
I'm going to close this as its understood behaviour and not a bug per-se,
though I agree the decision to use bbox_inches='tight' can cause
confusion.
I was still surprised that the aspect ratio of the figure was completely
changed. I would understand if some empty space were removed from all
sides, but in this case a lot of "empty" space was removed from the left
and right sides, but apparently not from the top and bottom?
Are you sure that's not a bug in the bbox_inches='tight' algorithm?
Here are a few updated screenshots. First, for comparison, two cases
repeated from above:
[image: image]
<https://user-images.githubusercontent.com/705404/74185869-c7679780-4c49-11ea-830e-82a592d9bba8.png>
And now without the bbox_inches='tight' setting:
[image: image]
<https://user-images.githubusercontent.com/705404/74185956-fc73ea00-4c49-11ea-9404-7726327a1ca5.png>
And here's how "normal" 2D plots look without the bbox_inches='tight'
setting:
[image: image]
<https://user-images.githubusercontent.com/705404/74186199-70ae8d80-4c4a-11ea-90be-790ea110d8be.png>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#16463?email_source=notifications&email_token=AACHF6D5ZP6WC3WP3JXVDS3RCGZR7A5CNFSM4KSR66V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELKECCI#issuecomment-584335625>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6BGVXC5SDPREJFCCGDRCGZR7ANCNFSM4KSR66VQ>
.
|
Thanks @WeatherGod, so are you saying this could be a bug? If yes, could you (or @jklymak) please re-open this issue? |
Hmm on my system everything works as expected: Windows 10 Seems to be a problem for newer releases, could reproduce it on 2bdf82b |
You might have a setting somewhere that turns off jupyter or ipython's auto
cropping setting.
…On Fri, Feb 21, 2020 at 2:29 PM Marat K. ***@***.***> wrote:
Hmm on my system everything works as expected:
[image: image]
<https://user-images.githubusercontent.com/12762439/75065122-817fbe80-54e8-11ea-8678-47bfb3f9423a.png>
Windows 10
Python 3.7.3
matplotlib-3.1.3
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16463?email_source=notifications&email_token=AACHF6DESLIYOCKE2ZQOVTDREATRVA5CNFSM4KSR66V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMT2HKY#issuecomment-589800363>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6BAGJBM3RELOLDOXITREATRVANCNFSM4KSR66VQ>
.
|
This bisects to 64f197b which has apparently been recreated via #16472. To make sure we're all on the same page here, let's take jupyter (lab) out of the equation and create a clear bug report here:
Actual outcome in 3.1.3direct save Outcome in current masterExpected outcomeThe direct save is expected. What's unexpected is the aspect ratio changing in the with |
ping @eric-wieser |
What does |
It trims the figure size to encompass just the 2d-plot. |
Should this block 3.2? Let's say yes for safety, but feel free to untag if you think not. |
That PR is only in master, so I don't think we need to block 3.2. That is, the outcome of @ImportanceOfBeingErnest's test on |
For me, this bug is only in Linux (Ubuntu), Windows saves images ok. |
ok, sorted out why this is happening. In matplotlib/lib/matplotlib/tight_bbox.py Lines 28 to 36 in 9ccdb1d
we freeze all of the axes postiions and set the aspect to auto for all of the axes having relied on a previous draw to have put them all in the right place. The next time we draw (for the render we actually emit) none of the axes adjust their positions / limits / etc and the transforms all progate through as we expect. Very previously Axes3D would do something about |
To make bbox_inches='tight' work correctly, we cache the positions of all of the axes, change their aspect to 'auto', adjust the transforms on the figure, render the output, and then restore the previous setting of aspect to each of the figures. This prevent the Axes from trying to adjust their size on draw. This matters because for the render that is emitted the figure transforms are out of sync with the figure size. As part of cleaning fixing the rendering of Axes3D in matplotlib#8896 / matplotlib#16472 we started to use apply_aspect to re-size the area the Axes3D takes up to maintain a fixed ratio between the axes when the aspect is "auto". However this conflicts with the expectation in tight_bbox.adjust_bbox as it assumes setting the aspect to "auto" will prevent any axes resizing. This commit addresses this by: - exiting the Axes3D.apply_aspect early if aspect is auto - adding a new aspect mode 'auto_pb' which is the default for Axes3D which maintains the current master branch behavior of maintaining a fixed ratio between the sizes of the x, y z axis independent of the data limits. - re implement several functions on Axes3D to make sure they handle sharez correctly. closes matplotlib#16463.
The way that bbox_inches='tight' is implemented we need to ensure that we do not try to adjust the aspect during the draw (because we have temporarily de-coupled the reported figure size from the transforms which results in the being distorted). Previously we did not have a way to fix the aspect ratio in screen space of the Axes (only the aspect ratio in dataspace) however in 3.3 we gained this ability for both Axes (matplotlib#14917) and Axes3D (matplotlib#8896 / matplotlib#16472). Rather than add an aspect value to `set_aspect` to handle this case, in the tight_bbox code we monkey-patch the `apply_aspect` method with a no-op function and then restore it when we are done. Previously we would set the aspect to "auto" and restore it in the same places. closes matplotlib#16463.
The way that bbox_inches='tight' is implemented we need to ensure that we do not try to adjust the aspect during the draw (because we have temporarily de-coupled the reported figure size from the transforms which results in the being distorted). Previously we did not have a way to fix the aspect ratio in screen space of the Axes (only the aspect ratio in dataspace) however in 3.3 we gained this ability for both Axes (matplotlib#14917) and Axes3D (matplotlib#8896 / matplotlib#16472). Rather than add an aspect value to `set_aspect` to handle this case, in the tight_bbox code we monkey-patch the `apply_aspect` method with a no-op function and then restore it when we are done. Previously we would set the aspect to "auto" and restore it in the same places. closes matplotlib#16463.
Hmm I'm still seeing this in fig = plt.figure(figsize=(20, 6))
fig.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=0, hspace=0)
ax = fig.add_subplot(111, projection="3d", facecolor='#000000', elev=70., azim=0, aspect='auto')
ax.axis('off')
ax.plot_surface(X, Y, S / 10, cmap=plt.get_cmap('magma')) No matter what I try I can't change the axis aspect ratio to fill the figure.
|
@beasteers I think you want https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.html#mpl_toolkits.mplot3d.axes3d.Axes3D.set_box_aspect Could you please post this at https://discourse.matplotlib.org (if you think it is a usage question) or open a new issue (if you think it is a bug)? |
I was observing exactly the same as @beasteers , Linux, python 3.10, Matplotlib 3.7.1.
|
I don't know if this is a bug in Jupyter/IPython or in Matplotlib ...
Bug report
Bug summary
When creating 3D plots (using
Axes3D
) with the "inline" backend (which is the default) in a Jupyter notebook, the argumentfigsize
doesn't seem to work as intended. It looks like the width is ignored when calculating the figure size (but it doesn't seem to be ignored when calculating the size of the "axes" object?).Actual outcome
First, when using
fig.gca(projection='3d')
, which is used in the official Matplotlib examples:The same thing happens when using
fig.add_subplot(projection='3d')
:Interestingly, a slightly different thing happens when using
fig.add_axes([0, 0, 1, 1], projection='3d')
andAxes3D(fig)
(which is discouraged?):Expected outcome
When using a "normal" 2D
Axes
, it looks as expected:The output from
fig.add_axes([0, 0, 1, 1])
is also different in this case:Matplotlib version
master
print(matplotlib.get_backend())
):module://ipykernel.pylab.backend_inline
master
The text was updated successfully, but these errors were encountered: