Skip to content

added rcParam for x and y margin #1908

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

Merged
merged 4 commits into from
Apr 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2013-04-15 Added 'axes.xmargin' and 'axes.ymargin' to rpParams to set default
margins on auto-scaleing. - TAC

2013-03-19 Added support for passing `linestyle` kwarg to `step` so all `plot`
kwargs are passed to the underlying `plot` call. -TAC

Expand Down
6 changes: 6 additions & 0 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ revision, see the :ref:`github-stats`.

new in matplotlib-1.3
=====================
``axes.xmargin`` and ``axes.ymargin`` added to rcParams
-------------------------------------------------------
``rcParam`` values (``axes.xmargin`` and ``axes.ymargin``) were added
to configure the default margins used. Previously they were
hard-coded to default to 0, default value of both rcParam values is 0.


New eventplot plot type
-------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,8 @@ def cla(self):

self._autoscaleXon = True
self._autoscaleYon = True
self._xmargin = 0
self._ymargin = 0
self._xmargin = rcParams['axes.xmargin']
self._ymargin = rcParams['axes.ymargin']
self._tight = False
self._update_transScale() # needed?

Expand Down Expand Up @@ -9076,7 +9076,7 @@ def matshow(self, Z, **kwargs):
return im

def get_default_bbox_extra_artists(self):
return [artist for artist in self.get_children()
return [artist for artist in self.get_children()
if artist.get_visible()]

def get_tightbbox(self, renderer, call_axes_locator=True):
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ def __call__(self, s):
'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
validate_colorlist], # cycle of plot
# line colors
'axes.xmargin': [0, ValidateInterval(0, 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the method is axes.margins (http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.margins), I'm tempted to suggest having an rcParam of axes.margins which has the same semantics as the method (i.e. (None, 0.1) is a valid margin setting).

Any thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

axes.margins is a dispatcher/convince function to set_xmargin and set_ymargin (which do not accept None as a valid input) and then calling autoscale_view to make sure everything updates. I think the rcParam should match the lower level.

Adding a third parameter axes.margins will allow the user to set it up to be inconsistent and we would need to sort out precedence which can only lead to confusion.

Looking at margins again, I think it might need a bit of work as axes.margins(.1, xmargin=.2) will set both margins to .1, which is not what I would expect. OTOH, this isn't really a documented call signature, but it will raise no errors.

closedmin=True,
closedmax=True)], # margin added to xaxis
'axes.ymargin': [0, ValidateInterval(0, 1,
closedmin=True,
closedmax=True)],# margin added to yaxis

'polaraxes.grid': [True, validate_bool], # display polar grid or
# not
Expand Down
4 changes: 3 additions & 1 deletion matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
# as list of string colorspecs:
# single letter, long name, or
# web-style hex
#axes.xmargin : 0 # x margin. See `axes.Axes.margins`
#axes.ymargin : 0 # y margin See `axes.Axes.margins`

#polaraxes.grid : True # display grid on polar axes
#axes3d.grid : True # display grid on 3d axes
Expand Down Expand Up @@ -451,7 +453,7 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
#animation.avconv_path: 'avconv' # Path to avconv binary. Without full path
# $PATH is searched
#animation.avconv_args: '' # Additional arguments to pass to avconv
#animation.mencoder_path: 'mencoder'
#animation.mencoder_path: 'mencoder'
# Path to mencoder binary. Without full path
# $PATH is searched
#animation.mencoder_args: '' # Additional arguments to pass to mencoder