-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: return the actual ax.get_window_extent #12716
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
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 @@ | ||
get_window_extents changes: | ||
--------------------------- | ||
|
||
`.matplotlib.axes.Axes.get_window_extent` used to return a bounding box | ||
that was slightly larger than the axes, presumably to take into account | ||
the ticks that may be on a spine. However, it was not scaling the tick sizes | ||
according to the dpi of the canvas, and it did not check if the ticks were | ||
visible, or on the spine. | ||
|
||
Now `.matplotlib.axes.Axes.get_window_extent` just returns the axes extent | ||
with no padding for ticks. | ||
|
||
This affects `.matplotlib.axes.Axes.get_tightbbox` in cases where there are | ||
outward ticks with no tick labels, and it also removes the (small) pad around | ||
axes in that case. | ||
|
||
`.spines.get_window_extent` now takes into account ticks that are on the | ||
spine. | ||
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -576,18 +576,21 @@ def __setstate__(self, state): | |||
|
||||
def get_window_extent(self, *args, **kwargs): | ||||
""" | ||||
get the axes bounding box in display space; *args* and | ||||
*kwargs* are empty | ||||
""" | ||||
bbox = self.bbox | ||||
x_pad = 0 | ||||
if self.axison and self.xaxis.get_visible(): | ||||
x_pad = self.xaxis.get_tick_padding() | ||||
y_pad = 0 | ||||
if self.axison and self.yaxis.get_visible(): | ||||
y_pad = self.yaxis.get_tick_padding() | ||||
return mtransforms.Bbox([[bbox.x0 - x_pad, bbox.y0 - y_pad], | ||||
[bbox.x1 + x_pad, bbox.y1 + y_pad]]) | ||||
Return the axes bounding box in display space; *args* and *kwargs* | ||||
are empty. | ||||
|
||||
This bounding box does not include the spines, ticks, ticklables, | ||||
or other labels. For a bounding box including these elements use | ||||
`~matplotlib.axes.Axes.get_tightbbox`. | ||||
|
||||
See Also | ||||
-------- | ||||
matplotlib.axes.Axes.get_tightbbox | ||||
matplotlib.axis.Axis.get_tightbbox | ||||
matplotlib.spines.get_window_extent | ||||
|
||||
""" | ||||
return self.bbox | ||||
|
||||
def _init_axis(self): | ||||
"move this out of __init__ because non-separable axes don't use it" | ||||
|
@@ -4286,6 +4289,13 @@ def get_tightbbox(self, renderer, call_axes_locator=True, | |||
------- | ||||
bbox : `.BboxBase` | ||||
bounding box in figure pixel coordinates. | ||||
|
||||
See Also | ||||
-------- | ||||
matplotlib.axis.Axes.get_window_extent | ||||
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. These extra 'See also' sections with non functional API links are breaking more strict docs builds downstream. (We run the docs build in our CI in astropy with the If it's helpful I can open a separate issue for this. 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. A new issue would get better traction. 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. We also run sphinx with Line 5 in 512aecb
so it is odd that astropy is failing but we are not... I suspect difference is sphinx versions (we are currently pinning to sphinx < 2 due to weird spacing at TOC and some breakage (which may be this)). It is also odd that this is not linking an the 'previous' link in the top right is the thing we want this to have linked to. Agree with @QuLogic , this should get it's own issue. |
||||
matplotlib.axis.Axis.get_tightbbox | ||||
matplotlib.spines.get_window_extent | ||||
|
||||
""" | ||||
|
||||
bb = [] | ||||
|
@@ -4300,13 +4310,14 @@ def get_tightbbox(self, renderer, call_axes_locator=True, | |||
else: | ||||
self.apply_aspect() | ||||
|
||||
bb_xaxis = self.xaxis.get_tightbbox(renderer) | ||||
if bb_xaxis: | ||||
bb.append(bb_xaxis) | ||||
if self.axison: | ||||
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. This change (self.axison), caused a few tests top change. So this is probably a breaking change. OTOH, I think its correct - it doesn't make sense to include the axis in the tight layout if its been turned off. 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. What about if not self.xaxis.get_visible()? (just asking) |
||||
bb_xaxis = self.xaxis.get_tightbbox(renderer) | ||||
if bb_xaxis: | ||||
bb.append(bb_xaxis) | ||||
|
||||
bb_yaxis = self.yaxis.get_tightbbox(renderer) | ||||
if bb_yaxis: | ||||
bb.append(bb_yaxis) | ||||
bb_yaxis = self.yaxis.get_tightbbox(renderer) | ||||
if bb_yaxis: | ||||
bb.append(bb_yaxis) | ||||
|
||||
self._update_title_position(renderer) | ||||
bb.append(self.get_window_extent(renderer)) | ||||
|
Uh oh!
There was an error while loading. Please reload this page.