Skip to content

Commit b530062

Browse files
committed
Merge branch 'v1.5.x' into v2.0.x
2 parents 7b0f9b0 + 6b30aaa commit b530062

File tree

12 files changed

+507
-202
lines changed

12 files changed

+507
-202
lines changed

doc/mpl_toolkits/axes_grid/api/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@
1313
axes_divider_api.rst
1414
axes_grid_api.rst
1515
axis_artist_api.rst
16+
17+
18+
#######################################
19+
The Matplotlib axes_grid1 Toolkit API
20+
#######################################
21+
22+
:Release: |version|
23+
:Date: |today|
24+
25+
.. toctree::
26+
27+
inset_locator_api.rst
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:mod:`mpl_toolkits.axes_grid1.inset_locator`
2+
============================================
3+
4+
.. automodule:: mpl_toolkits.axes_grid1.inset_locator
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

lib/matplotlib/cbook.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ class Grouper(object):
15591559
False
15601560
15611561
"""
1562-
def __init__(self, init=[]):
1562+
def __init__(self, init=()):
15631563
mapping = self._mapping = {}
15641564
for x in init:
15651565
mapping[ref(x)] = [ref(x)]
@@ -1611,6 +1611,14 @@ def joined(self, a, b):
16111611
except KeyError:
16121612
return False
16131613

1614+
def remove(self, a):
1615+
self.clean()
1616+
1617+
mapping = self._mapping
1618+
seta = mapping.pop(ref(a), None)
1619+
if seta is not None:
1620+
seta.remove(ref(a))
1621+
16141622
def __iter__(self):
16151623
"""
16161624
Iterate over each of the disjoint sets as a list.

lib/matplotlib/figure.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ def add_axes(self, *args, **kwargs):
917917

918918
self._axstack.add(key, a)
919919
self.sca(a)
920-
a._remove_method = lambda ax: self.delaxes(ax)
920+
a._remove_method = self.__remove_ax
921921
self.stale = True
922922
a.stale_callback = _stale_figure_callback
923923
return a
@@ -1007,7 +1007,7 @@ def add_subplot(self, *args, **kwargs):
10071007

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

1147+
def __remove_ax(self, ax):
1148+
def _reset_loc_form(axis):
1149+
axis.set_major_formatter(axis.get_major_formatter())
1150+
axis.set_major_locator(axis.get_major_locator())
1151+
axis.set_minor_formatter(axis.get_minor_formatter())
1152+
axis.set_minor_locator(axis.get_minor_locator())
1153+
1154+
def _break_share_link(ax, grouper):
1155+
siblings = grouper.get_siblings(ax)
1156+
if len(siblings) > 1:
1157+
grouper.remove(ax)
1158+
for last_ax in siblings:
1159+
if ax is last_ax:
1160+
continue
1161+
return last_ax
1162+
return None
1163+
1164+
self.delaxes(ax)
1165+
last_ax = _break_share_link(ax, ax._shared_y_axes)
1166+
if last_ax is not None:
1167+
_reset_loc_form(last_ax.yaxis)
1168+
1169+
last_ax = _break_share_link(ax, ax._shared_x_axes)
1170+
if last_ax is not None:
1171+
_reset_loc_form(last_ax.xaxis)
1172+
11471173
def clf(self, keep_observers=False):
11481174
"""
11491175
Clear the figure.

lib/matplotlib/tests/test_axes.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,6 +4197,49 @@ def test_auto_numticks():
41974197
fig, axes = plt.subplots(4, 4)
41984198

41994199

4200+
def test_remove_shared_axes():
4201+
def _helper_x(ax):
4202+
ax2 = ax.twinx()
4203+
ax2.remove()
4204+
ax.set_xlim(0, 15)
4205+
r = ax.xaxis.get_major_locator()()
4206+
assert r[-1] > 14
4207+
4208+
def _helper_y(ax):
4209+
ax2 = ax.twiny()
4210+
ax2.remove()
4211+
ax.set_ylim(0, 15)
4212+
r = ax.yaxis.get_major_locator()()
4213+
assert r[-1] > 14
4214+
4215+
# test all of the ways to get fig/ax sets
4216+
fig = plt.figure()
4217+
ax = fig.gca()
4218+
yield _helper_x, ax
4219+
yield _helper_y, ax
4220+
4221+
fig, ax = plt.subplots()
4222+
yield _helper_x, ax
4223+
yield _helper_y, ax
4224+
4225+
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
4226+
ax = ax_lst[0][0]
4227+
yield _helper_x, ax
4228+
yield _helper_y, ax
4229+
4230+
fig = plt.figure()
4231+
ax = fig.add_axes([.1, .1, .8, .8])
4232+
yield _helper_x, ax
4233+
yield _helper_y, ax
4234+
4235+
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
4236+
ax = ax_lst[0][0]
4237+
orig_xlim = ax_lst[0][1].get_xlim()
4238+
ax.remove()
4239+
ax.set_xlim(0, 5)
4240+
assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)
4241+
4242+
42004243
if __name__ == '__main__':
42014244
import nose
42024245
import sys

lib/matplotlib/tests/test_cbook.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3+
import itertools
4+
from weakref import ref
35

46
from matplotlib.externals import six
57

@@ -376,3 +378,40 @@ def test_step_fails():
376378
np.arange(12))
377379
assert_raises(ValueError, cbook._step_validation,
378380
np.arange(12), np.arange(3))
381+
382+
383+
def test_grouper():
384+
class dummy():
385+
pass
386+
a, b, c, d, e = objs = [dummy() for j in range(5)]
387+
g = cbook.Grouper()
388+
g.join(*objs)
389+
assert set(list(g)[0]) == set(objs)
390+
assert set(g.get_siblings(a)) == set(objs)
391+
392+
for other in objs[1:]:
393+
assert g.joined(a, other)
394+
395+
g.remove(a)
396+
for other in objs[1:]:
397+
assert not g.joined(a, other)
398+
399+
for A, B in itertools.product(objs[1:], objs[1:]):
400+
assert g.joined(A, B)
401+
402+
403+
def test_grouper_private():
404+
class dummy():
405+
pass
406+
objs = [dummy() for j in range(5)]
407+
g = cbook.Grouper()
408+
g.join(*objs)
409+
# reach in and touch the internals !
410+
mapping = g._mapping
411+
412+
for o in objs:
413+
assert ref(o) in mapping
414+
415+
base_set = mapping[ref(objs[0])]
416+
for o in objs[1:]:
417+
assert mapping[ref(o)] is base_set

lib/matplotlib/ticker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ def set_offset_string(self, ofs):
326326
class FuncFormatter(Formatter):
327327
"""
328328
User defined function for formatting
329+
330+
The function should take in two inputs (tick value *x* and position *pos*)
331+
and return a string
329332
"""
330333
def __init__(self, func):
331334
self.func = func

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ def __init__(self, ax, cmap=None,
374374
if format is None:
375375
if isinstance(self.norm, colors.LogNorm):
376376
# change both axis for proper aspect
377-
self.ax.xaxis.set_scale("log")
378-
self.ax.yaxis.set_scale("log")
379-
self.ax._update_transScale()
377+
self.ax.set_xscale("log")
378+
self.ax.set_yscale("log")
380379
self.cbar_axis.set_minor_locator(ticker.NullLocator())
381380
formatter = ticker.LogFormatter()
382381
else:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy