-
Notifications
You must be signed in to change notification settings - Fork 153
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
Don’t use tight layout as it causes bouncing around of axes #745
Changes from 6 commits
5f452f8
05443b8
b542933
37ab4b3
2a252de
06480f1
60e6e58
067a27c
9be3186
fc595ec
f023710
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 |
---|---|---|
|
@@ -176,3 +176,44 @@ def point_contour(x, y, data): | |
return None | ||
xy = xy[0] | ||
return xy | ||
|
||
|
||
class AxesResizer(object): | ||
|
||
def __init__(self, ax, margins): | ||
|
||
self.ax = ax | ||
self.margins = margins | ||
|
||
def on_resize(self, event): | ||
|
||
fig_width = self.ax.figure.get_figwidth() | ||
fig_height = self.ax.figure.get_figheight() | ||
|
||
x0 = self.margins[0] / fig_width | ||
x1 = 1 - self.margins[1] / fig_width | ||
y0 = self.margins[2] / fig_height | ||
y1 = 1 - self.margins[3] / fig_height | ||
|
||
dx = max(0.01, x1 - x0) | ||
dy = max(0.01, y1 - y0) | ||
|
||
self.ax.set_position([x0, y0, dx, dy]) | ||
self.ax.figure.canvas.draw() | ||
|
||
|
||
def fix_margins(axes, margins=[1, 1, 1, 1]): | ||
""" | ||
Make sure margins of axes stay fixed. | ||
|
||
Parameters | ||
---------- | ||
ax_class : matplotlib.axes.Axes | ||
The axes class for which to fix the margins | ||
margins : iterable | ||
The margins, in inches. The order of the margins is | ||
``[left, right, bottom, top]`` | ||
""" | ||
|
||
resizer = AxesResizer(axes, margins) | ||
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. it might be nice to store this resizer as an attribute on the axes somewhere, in case downstream code wishes to modify it. 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. Hmm, that might be a way to customize the margins then, if it's accessible as 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 don't think we should worry about future name clashes with resizer On Friday, September 11, 2015, Thomas Robitaille notifications@github.com
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. Done :) |
||
axes.figure.canvas.mpl_connect('resize_event', resizer.on_resize) |
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.
what do you think about the name
freeze_margins
?fix
could be interpreted as implying that the default isbroken
.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.
Yes, sounds good
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.
Fixed