Skip to content

Commit

Permalink
Merge branch 'v1.5.x' into v2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Dec 17, 2015
2 parents 7b0f9b0 + 6b30aaa commit b530062
Show file tree
Hide file tree
Showing 12 changed files with 507 additions and 202 deletions.
12 changes: 12 additions & 0 deletions doc/mpl_toolkits/axes_grid/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@
axes_divider_api.rst
axes_grid_api.rst
axis_artist_api.rst


#######################################
The Matplotlib axes_grid1 Toolkit API
#######################################

:Release: |version|
:Date: |today|

.. toctree::

inset_locator_api.rst
7 changes: 7 additions & 0 deletions doc/mpl_toolkits/axes_grid/api/inset_locator_api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:mod:`mpl_toolkits.axes_grid1.inset_locator`
============================================

.. automodule:: mpl_toolkits.axes_grid1.inset_locator
:members:
:undoc-members:
:show-inheritance:
10 changes: 9 additions & 1 deletion lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ class Grouper(object):
False
"""
def __init__(self, init=[]):
def __init__(self, init=()):
mapping = self._mapping = {}
for x in init:
mapping[ref(x)] = [ref(x)]
Expand Down Expand Up @@ -1611,6 +1611,14 @@ def joined(self, a, b):
except KeyError:
return False

def remove(self, a):
self.clean()

mapping = self._mapping
seta = mapping.pop(ref(a), None)
if seta is not None:
seta.remove(ref(a))

def __iter__(self):
"""
Iterate over each of the disjoint sets as a list.
Expand Down
30 changes: 28 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ def add_axes(self, *args, **kwargs):

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
a._remove_method = self.__remove_ax
self.stale = True
a.stale_callback = _stale_figure_callback
return a
Expand Down Expand Up @@ -1007,7 +1007,7 @@ def add_subplot(self, *args, **kwargs):

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
a._remove_method = self.__remove_ax
self.stale = True
a.stale_callback = _stale_figure_callback
return a
Expand Down Expand Up @@ -1144,6 +1144,32 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
# Returned axis array will be always 2-d, even if nrows=ncols=1.
return axarr

def __remove_ax(self, ax):
def _reset_loc_form(axis):
axis.set_major_formatter(axis.get_major_formatter())
axis.set_major_locator(axis.get_major_locator())
axis.set_minor_formatter(axis.get_minor_formatter())
axis.set_minor_locator(axis.get_minor_locator())

def _break_share_link(ax, grouper):
siblings = grouper.get_siblings(ax)
if len(siblings) > 1:
grouper.remove(ax)
for last_ax in siblings:
if ax is last_ax:
continue
return last_ax
return None

self.delaxes(ax)
last_ax = _break_share_link(ax, ax._shared_y_axes)
if last_ax is not None:
_reset_loc_form(last_ax.yaxis)

last_ax = _break_share_link(ax, ax._shared_x_axes)
if last_ax is not None:
_reset_loc_form(last_ax.xaxis)

def clf(self, keep_observers=False):
"""
Clear the figure.
Expand Down
43 changes: 43 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4197,6 +4197,49 @@ def test_auto_numticks():
fig, axes = plt.subplots(4, 4)


def test_remove_shared_axes():
def _helper_x(ax):
ax2 = ax.twinx()
ax2.remove()
ax.set_xlim(0, 15)
r = ax.xaxis.get_major_locator()()
assert r[-1] > 14

def _helper_y(ax):
ax2 = ax.twiny()
ax2.remove()
ax.set_ylim(0, 15)
r = ax.yaxis.get_major_locator()()
assert r[-1] > 14

# test all of the ways to get fig/ax sets
fig = plt.figure()
ax = fig.gca()
yield _helper_x, ax
yield _helper_y, ax

fig, ax = plt.subplots()
yield _helper_x, ax
yield _helper_y, ax

fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
ax = ax_lst[0][0]
yield _helper_x, ax
yield _helper_y, ax

fig = plt.figure()
ax = fig.add_axes([.1, .1, .8, .8])
yield _helper_x, ax
yield _helper_y, ax

fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
ax = ax_lst[0][0]
orig_xlim = ax_lst[0][1].get_xlim()
ax.remove()
ax.set_xlim(0, 5)
assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)


if __name__ == '__main__':
import nose
import sys
Expand Down
39 changes: 39 additions & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import itertools
from weakref import ref

from matplotlib.externals import six

Expand Down Expand Up @@ -376,3 +378,40 @@ def test_step_fails():
np.arange(12))
assert_raises(ValueError, cbook._step_validation,
np.arange(12), np.arange(3))


def test_grouper():
class dummy():
pass
a, b, c, d, e = objs = [dummy() for j in range(5)]
g = cbook.Grouper()
g.join(*objs)
assert set(list(g)[0]) == set(objs)
assert set(g.get_siblings(a)) == set(objs)

for other in objs[1:]:
assert g.joined(a, other)

g.remove(a)
for other in objs[1:]:
assert not g.joined(a, other)

for A, B in itertools.product(objs[1:], objs[1:]):
assert g.joined(A, B)


def test_grouper_private():
class dummy():
pass
objs = [dummy() for j in range(5)]
g = cbook.Grouper()
g.join(*objs)
# reach in and touch the internals !
mapping = g._mapping

for o in objs:
assert ref(o) in mapping

base_set = mapping[ref(objs[0])]
for o in objs[1:]:
assert mapping[ref(o)] is base_set
3 changes: 3 additions & 0 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ def set_offset_string(self, ofs):
class FuncFormatter(Formatter):
"""
User defined function for formatting
The function should take in two inputs (tick value *x* and position *pos*)
and return a string
"""
def __init__(self, func):
self.func = func
Expand Down
5 changes: 2 additions & 3 deletions lib/mpl_toolkits/axes_grid1/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,8 @@ def __init__(self, ax, cmap=None,
if format is None:
if isinstance(self.norm, colors.LogNorm):
# change both axis for proper aspect
self.ax.xaxis.set_scale("log")
self.ax.yaxis.set_scale("log")
self.ax._update_transScale()
self.ax.set_xscale("log")
self.ax.set_yscale("log")
self.cbar_axis.set_minor_locator(ticker.NullLocator())
formatter = ticker.LogFormatter()
else:
Expand Down

0 comments on commit b530062

Please sign in to comment.