Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Do not add padding to 3D axis limits when limits are manually set#25272
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Setting 3D axis limits now set the limits exactly | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| Previously, setting the limits of a 3D axis would always add a small margin to | ||
| the limits. Limits are now set exactly by default. The newly introduced rcparam | ||
| ``axes3d.automargin`` can be used to revert to the old behavior where margin is | ||
| automatically added. | ||
| ..plot:: | ||
| :include-source: true | ||
| :alt: Example of the new behavior of 3D axis limits, and how setting the rcparam reverts to the old behavior. | ||
| import matplotlib.pyplot as plt | ||
| fig, axs = plt.subplots(1, 2, subplot_kw={'projection': '3d'}) | ||
| plt.rcParams['axes3d.automargin'] = False # the default in 3.9.0 | ||
| axs[0].set(xlim=(0, 1), ylim=(0, 1), zlim=(0, 1), title='New Behavior') | ||
| plt.rcParams['axes3d.automargin'] = True | ||
| axs[1].set(xlim=(0, 1), ylim=(0, 1), zlim=(0, 1), title='Old Behavior') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -855,13 +855,14 @@ def _get_autoscale_on(self): | ||
| def _set_autoscale_on(self, b): | ||
| """ | ||
| Set whether this Axis is autoscaled when drawing or by | ||
| `.Axes.autoscale_view`. If b is None, then the value is not changed. | ||
scottshambaugh marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Parameters | ||
| ---------- | ||
| b : bool | ||
| """ | ||
| if b is not None: | ||
| self._autoscale_on = b | ||
| def get_children(self): | ||
| return [self.label, self.offsetText, | ||
| @@ -1244,8 +1245,7 @@ def _set_lim(self, v0, v1, *, emit=True, auto): | ||
| # Mark viewlims as no longer stale without triggering an autoscale. | ||
| for ax in self._get_shared_axes(): | ||
| ax._stale_viewlims[name] = False | ||
| self._set_autoscale_on(auto) | ||
| if emit: | ||
| self.axes.callbacks.process(f"{name}lim_changed", self.axes) | ||
| @@ -1292,6 +1292,17 @@ def _update_ticks(self): | ||
| if view_low > view_high: | ||
| view_low, view_high = view_high, view_low | ||
| if (hasattr(self, "axes") and self.axes.name == '3d' | ||
| and mpl.rcParams['axes3d.automargin']): | ||
| # In mpl3.8, the margin was 1/48. Due to the change in automargin | ||
| # behavior in mpl3.9, we need to adjust this to compensate for a | ||
| # zoom factor of 2/48, giving us a 23/24 modifier. So the new | ||
| # margin is 0.019965277777777776 = 1/48*23/24. | ||
| margin = 0.019965277777777776 | ||
| delta = view_high - view_low | ||
| view_high = view_high - delta * margin | ||
| view_low = view_low + delta * margin | ||
| interval_t = self.get_transform().transform([view_low, view_high]) | ||
| ticks_to_draw = [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -425,8 +425,9 @@ | ||
| #axes.autolimit_mode: data # If "data", use axes.xmargin and axes.ymargin as is. | ||
| # If "round_numbers", after application of margins, axis | ||
| # limits are further expanded to the nearest "round" number. | ||
| #polaraxes.grid: True # display grid on polar axes | ||
| #axes3d.grid: True # display grid on 3D axes | ||
| #axes3d.automargin: False # automatically add margin when manually setting 3D axis limits | ||
scottshambaugh marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| #axes3d.xaxis.panecolor: (0.95, 0.95, 0.95, 0.5) # background pane on 3D axes | ||
| #axes3d.yaxis.panecolor: (0.90, 0.90, 0.90, 0.5) # background pane on 3D axes | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -401,6 +401,7 @@ def test_EllipseCollection(): | ||
| @image_comparison(['polycollection_close.png'],remove_text=True,style='mpl20') | ||
| deftest_polycollection_close(): | ||
| frommpl_toolkits.mplot3dimportAxes3D# type: ignore | ||
| plt.rcParams['axes3d.automargin']=True | ||
scottshambaugh marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| vertsQuad= [ | ||
| [[0.,0.], [0.,1.], [1.,1.], [1.,0.]], | ||
Uh oh!
There was an error while loading.Please reload this page.