Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8435e5

Browse files
committed
Merge remote-tracking branch 'upstream/master' into add_doc
2 parents 3570f12 + 564d4fd commit c8435e5

File tree

12 files changed

+176
-108
lines changed

12 files changed

+176
-108
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Rename fist arg to subplot_mosaic
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Both `.FigureBase.subplot_mosaic`, and `.pyplot.subplot_mosaic` have had the
5+
first position argument renamed from *layout* to *mosaic*. This is because we
6+
are considering to consolidate *constrained_layout* and *tight_layout* keyword
7+
arguments in the Figure creation functions of `.pyplot` into a single *layout*
8+
keyword argument which would collide.
9+
10+
As this API is provisional, we are changing this with no deprecation period.

doc/contents.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Overview
1818
faq/index.rst
1919
api/index.rst
2020
resources/index.rst
21-
thirdpartypackages/index.rst
21+
Third-party packages <https://matplotlib.org/mpl-third-party/>
2222
devel/index.rst
2323

2424
.. only:: html

doc/devel/documenting_mpl.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ Including figures and files
290290
---------------------------
291291

292292
Image files can directly included in pages with the ``image::`` directive.
293-
e.g., :file:`thirdpartypackages/index.rst` displays the images for the third-party
294-
packages as static images::
293+
e.g., :file:`tutorials/intermediate/constrainedlayout_guide.py` displays
294+
a couple of static images::
295295

296-
.. image:: /_static/toolbar.png
296+
# .. image:: /_static/constrained_layout_1b.png
297+
# :align: center
297298

298-
as rendered on the page: :ref:`thirdparty-index`.
299299

300300
Files can be included verbatim. For instance the ``LICENSE`` file is included
301301
at :ref:`license-agreement` using ::

doc/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Matplotlib makes easy things easy and hard things possible.
6363
Extend
6464

6565
- Explore tailored functionality provided by
66-
:doc:`third party packages <thirdpartypackages/index>`
66+
`third party packages <https://matplotlib.org/mpl-third-party/>`_
6767
- Learn more about Matplotlib through the many
6868
:doc:`external learning resources <resources/index>`
6969

@@ -162,7 +162,8 @@ helpers in `.axisartist`.
162162
Third party packages
163163
====================
164164

165-
A large number of :doc:`third party packages <thirdpartypackages/index>`
165+
A large number of
166+
`third party packages <https://matplotlib.org/mpl-third-party/>`_
166167
extend and build on Matplotlib functionality, including several higher-level
167168
plotting interfaces (seaborn_, HoloViews_, ggplot_, ...), and a projection
168169
and mapping toolkit (Cartopy_).

doc/thirdpartypackages/index.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
.. _thirdparty-index:
1+
:orphan:
2+
3+
.. note::
4+
5+
This page has been moved to <https://matplotlib.org/mpl-third-party>,
6+
where you will find an up-to-date list of packages.
7+
28

39
********************
410
Third party packages

lib/matplotlib/axis.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,18 @@ def get_children(self):
786786
return [self.label, self.offsetText,
787787
*self.get_major_ticks(), *self.get_minor_ticks()]
788788

789+
def _reset_major_tick_kw(self):
790+
self._major_tick_kw.clear()
791+
self._major_tick_kw['gridOn'] = (
792+
mpl.rcParams['axes.grid'] and
793+
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
794+
795+
def _reset_minor_tick_kw(self):
796+
self._minor_tick_kw.clear()
797+
self._minor_tick_kw['gridOn'] = (
798+
mpl.rcParams['axes.grid'] and
799+
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
800+
789801
def clear(self):
790802
"""
791803
Clear the axis.
@@ -807,14 +819,8 @@ def clear(self):
807819
# Clear the callback registry for this axis, or it may "leak"
808820
self.callbacks = cbook.CallbackRegistry()
809821

810-
# whether the grids are on
811-
self._major_tick_kw['gridOn'] = (
812-
mpl.rcParams['axes.grid'] and
813-
mpl.rcParams['axes.grid.which'] in ('both', 'major'))
814-
self._minor_tick_kw['gridOn'] = (
815-
mpl.rcParams['axes.grid'] and
816-
mpl.rcParams['axes.grid.which'] in ('both', 'minor'))
817-
822+
self._reset_major_tick_kw()
823+
self._reset_minor_tick_kw()
818824
self.reset_ticks()
819825

820826
self.converter = None
@@ -861,10 +867,10 @@ def set_tick_params(self, which='major', reset=False, **kw):
861867
# future new ticks will automatically get them
862868
if reset:
863869
if which in ['major', 'both']:
864-
self._major_tick_kw.clear()
870+
self._reset_major_tick_kw()
865871
self._major_tick_kw.update(kwtrans)
866872
if which in ['minor', 'both']:
867-
self._minor_tick_kw.clear()
873+
self._reset_minor_tick_kw()
868874
self._minor_tick_kw.update(kwtrans)
869875
self.reset_ticks()
870876
else:
@@ -1413,35 +1419,40 @@ def grid(self, b=None, which='major', **kwargs):
14131419
14141420
grid(color='r', linestyle='-', linewidth=2)
14151421
"""
1416-
if b is not None:
1417-
if 'visible' in kwargs and bool(b) != bool(kwargs['visible']):
1422+
TOGGLE = object()
1423+
UNSET = object()
1424+
visible = kwargs.pop('visible', UNSET)
1425+
1426+
if b is None:
1427+
if visible is UNSET:
1428+
if kwargs: # grid(color='r')
1429+
b = True
1430+
else: # grid()
1431+
b = TOGGLE
1432+
else: # grid(visible=v)
1433+
b = visible
1434+
else:
1435+
if visible is not UNSET and bool(b) != bool(visible):
1436+
# grid(True, visible=False), grid(False, visible=True)
14181437
raise ValueError(
14191438
"'b' and 'visible' specify inconsistent grid visibilities")
14201439
if kwargs and not b: # something false-like but not None
1440+
# grid(0, visible=True)
14211441
_api.warn_external('First parameter to grid() is false, '
14221442
'but line properties are supplied. The '
14231443
'grid will be enabled.')
14241444
b = True
1445+
14251446
which = which.lower()
14261447
_api.check_in_list(['major', 'minor', 'both'], which=which)
14271448
gridkw = {'grid_' + item[0]: item[1] for item in kwargs.items()}
1428-
if 'grid_visible' in gridkw:
1429-
forced_visibility = True
1430-
gridkw['gridOn'] = gridkw.pop('grid_visible')
1431-
else:
1432-
forced_visibility = False
1433-
14341449
if which in ['minor', 'both']:
1435-
if b is None and not forced_visibility:
1436-
gridkw['gridOn'] = not self._minor_tick_kw['gridOn']
1437-
elif b is not None:
1438-
gridkw['gridOn'] = b
1450+
gridkw['gridOn'] = (not self._minor_tick_kw['gridOn']
1451+
if b is TOGGLE else b)
14391452
self.set_tick_params(which='minor', **gridkw)
14401453
if which in ['major', 'both']:
1441-
if b is None and not forced_visibility:
1442-
gridkw['gridOn'] = not self._major_tick_kw['gridOn']
1443-
elif b is not None:
1444-
gridkw['gridOn'] = b
1454+
gridkw['gridOn'] = (not self._major_tick_kw['gridOn']
1455+
if b is TOGGLE else b)
14451456
self.set_tick_params(which='major', **gridkw)
14461457
self.stale = True
14471458

lib/matplotlib/figure.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ def _normalize_grid_string(layout):
16491649
layout = inspect.cleandoc(layout)
16501650
return [list(ln) for ln in layout.strip('\n').split('\n')]
16511651

1652-
def subplot_mosaic(self, layout, *, sharex=False, sharey=False,
1652+
def subplot_mosaic(self, mosaic, *, sharex=False, sharey=False,
16531653
subplot_kw=None, gridspec_kw=None, empty_sentinel='.'):
16541654
"""
16551655
Build a layout of Axes based on ASCII art or nested lists.
@@ -1663,7 +1663,7 @@ def subplot_mosaic(self, layout, *, sharex=False, sharey=False,
16631663
16641664
Parameters
16651665
----------
1666-
layout : list of list of {hashable or nested} or str
1666+
mosaic : list of list of {hashable or nested} or str
16671667
16681668
A visual layout of how you want your Axes to be arranged
16691669
labeled as strings. For example ::
@@ -1728,8 +1728,8 @@ def subplot_mosaic(self, layout, *, sharex=False, sharey=False,
17281728
subplot_kw = subplot_kw or {}
17291729
gridspec_kw = gridspec_kw or {}
17301730
# special-case string input
1731-
if isinstance(layout, str):
1732-
layout = self._normalize_grid_string(layout)
1731+
if isinstance(mosaic, str):
1732+
mosaic = self._normalize_grid_string(mosaic)
17331733
# Only accept strict bools to allow a possible future API expansion.
17341734
_api.check_isinstance(bool, sharex=sharex, sharey=sharey)
17351735

@@ -1749,10 +1749,10 @@ def _make_array(inp):
17491749
"""
17501750
r0, *rest = inp
17511751
if isinstance(r0, str):
1752-
raise ValueError('List layout specification must be 2D')
1752+
raise ValueError('List mosaic specification must be 2D')
17531753
for j, r in enumerate(rest, start=1):
17541754
if isinstance(r, str):
1755-
raise ValueError('List layout specification must be 2D')
1755+
raise ValueError('List mosaic specification must be 2D')
17561756
if len(r0) != len(r):
17571757
raise ValueError(
17581758
"All of the rows must be the same length, however "
@@ -1765,24 +1765,24 @@ def _make_array(inp):
17651765
out[j, k] = v
17661766
return out
17671767

1768-
def _identify_keys_and_nested(layout):
1768+
def _identify_keys_and_nested(mosaic):
17691769
"""
1770-
Given a 2D object array, identify unique IDs and nested layouts
1770+
Given a 2D object array, identify unique IDs and nested mosaics
17711771
17721772
Parameters
17731773
----------
1774-
layout : 2D numpy object array
1774+
mosaic : 2D numpy object array
17751775
17761776
Returns
17771777
-------
17781778
unique_ids : tuple
1779-
The unique non-sub layout entries in this layout
1779+
The unique non-sub mosaic entries in this mosaic
17801780
nested : dict[tuple[int, int]], 2D object array
17811781
"""
17821782
# make sure we preserve the user supplied order
17831783
unique_ids = cbook._OrderedSet()
17841784
nested = {}
1785-
for j, row in enumerate(layout):
1785+
for j, row in enumerate(mosaic):
17861786
for k, v in enumerate(row):
17871787
if v == empty_sentinel:
17881788
continue
@@ -1793,102 +1793,102 @@ def _identify_keys_and_nested(layout):
17931793

17941794
return tuple(unique_ids), nested
17951795

1796-
def _do_layout(gs, layout, unique_ids, nested):
1796+
def _do_layout(gs, mosaic, unique_ids, nested):
17971797
"""
1798-
Recursively do the layout.
1798+
Recursively do the mosaic.
17991799
18001800
Parameters
18011801
----------
18021802
gs : GridSpec
1803-
layout : 2D object array
1803+
mosaic : 2D object array
18041804
The input converted to a 2D numpy array for this level.
18051805
unique_ids : tuple
18061806
The identified scalar labels at this level of nesting.
18071807
nested : dict[tuple[int, int]], 2D object array
1808-
The identified nested layouts, if any.
1808+
The identified nested mosaics, if any.
18091809
18101810
Returns
18111811
-------
18121812
dict[label, Axes]
18131813
A flat dict of all of the Axes created.
18141814
"""
1815-
rows, cols = layout.shape
1815+
rows, cols = mosaic.shape
18161816
output = dict()
18171817

18181818
# we need to merge together the Axes at this level and the axes
1819-
# in the (recursively) nested sub-layouts so that we can add
1819+
# in the (recursively) nested sub-mosaics so that we can add
18201820
# them to the figure in the "natural" order if you were to
18211821
# ravel in c-order all of the Axes that will be created
18221822
#
18231823
# This will stash the upper left index of each object (axes or
1824-
# nested layout) at this level
1824+
# nested mosaic) at this level
18251825
this_level = dict()
18261826

18271827
# go through the unique keys,
18281828
for name in unique_ids:
18291829
# sort out where each axes starts/ends
1830-
indx = np.argwhere(layout == name)
1830+
indx = np.argwhere(mosaic == name)
18311831
start_row, start_col = np.min(indx, axis=0)
18321832
end_row, end_col = np.max(indx, axis=0) + 1
18331833
# and construct the slice object
18341834
slc = (slice(start_row, end_row), slice(start_col, end_col))
18351835
# some light error checking
1836-
if (layout[slc] != name).any():
1836+
if (mosaic[slc] != name).any():
18371837
raise ValueError(
1838-
f"While trying to layout\n{layout!r}\n"
1838+
f"While trying to layout\n{mosaic!r}\n"
18391839
f"we found that the label {name!r} specifies a "
18401840
"non-rectangular or non-contiguous area.")
18411841
# and stash this slice for later
18421842
this_level[(start_row, start_col)] = (name, slc, 'axes')
18431843

1844-
# do the same thing for the nested layouts (simpler because these
1844+
# do the same thing for the nested mosaics (simpler because these
18451845
# can not be spans yet!)
1846-
for (j, k), nested_layout in nested.items():
1847-
this_level[(j, k)] = (None, nested_layout, 'nested')
1846+
for (j, k), nested_mosaic in nested.items():
1847+
this_level[(j, k)] = (None, nested_mosaic, 'nested')
18481848

18491849
# now go through the things in this level and add them
18501850
# in order left-to-right top-to-bottom
18511851
for key in sorted(this_level):
18521852
name, arg, method = this_level[key]
18531853
# we are doing some hokey function dispatch here based
18541854
# on the 'method' string stashed above to sort out if this
1855-
# element is an axes or a nested layout.
1855+
# element is an axes or a nested mosaic.
18561856
if method == 'axes':
18571857
slc = arg
18581858
# add a single axes
18591859
if name in output:
18601860
raise ValueError(f"There are duplicate keys {name} "
1861-
f"in the layout\n{layout!r}")
1861+
f"in the layout\n{mosaic!r}")
18621862
ax = self.add_subplot(
18631863
gs[slc], **{'label': str(name), **subplot_kw}
18641864
)
18651865
output[name] = ax
18661866
elif method == 'nested':
1867-
nested_layout = arg
1867+
nested_mosaic = arg
18681868
j, k = key
1869-
# recursively add the nested layout
1870-
rows, cols = nested_layout.shape
1869+
# recursively add the nested mosaic
1870+
rows, cols = nested_mosaic.shape
18711871
nested_output = _do_layout(
18721872
gs[j, k].subgridspec(rows, cols, **gridspec_kw),
1873-
nested_layout,
1874-
*_identify_keys_and_nested(nested_layout)
1873+
nested_mosaic,
1874+
*_identify_keys_and_nested(nested_mosaic)
18751875
)
18761876
overlap = set(output) & set(nested_output)
18771877
if overlap:
18781878
raise ValueError(
18791879
f"There are duplicate keys {overlap} "
1880-
f"between the outer layout\n{layout!r}\n"
1881-
f"and the nested layout\n{nested_layout}"
1880+
f"between the outer layout\n{mosaic!r}\n"
1881+
f"and the nested layout\n{nested_mosaic}"
18821882
)
18831883
output.update(nested_output)
18841884
else:
18851885
raise RuntimeError("This should never happen")
18861886
return output
18871887

1888-
layout = _make_array(layout)
1889-
rows, cols = layout.shape
1888+
mosaic = _make_array(mosaic)
1889+
rows, cols = mosaic.shape
18901890
gs = self.add_gridspec(rows, cols, **gridspec_kw)
1891-
ret = _do_layout(gs, layout, *_identify_keys_and_nested(layout))
1891+
ret = _do_layout(gs, mosaic, *_identify_keys_and_nested(mosaic))
18921892
ax0 = next(iter(ret.values()))
18931893
for ax in ret.values():
18941894
if sharex:

lib/matplotlib/gridspec.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,13 @@ def subplots(self, *, sharex=False, sharey=False, squeeze=True,
308308
self[row, col], **subplot_kw)
309309

310310
# turn off redundant tick labeling
311-
if sharex in ["col", "all"]:
312-
for ax in axarr.flat:
313-
ax._label_outer_xaxis()
314-
if sharey in ["row", "all"]:
315-
for ax in axarr.flat:
316-
ax._label_outer_yaxis()
311+
if all(ax.name == "rectilinear" for ax in axarr.flat):
312+
if sharex in ["col", "all"]:
313+
for ax in axarr.flat:
314+
ax._label_outer_xaxis()
315+
if sharey in ["row", "all"]:
316+
for ax in axarr.flat:
317+
ax._label_outer_yaxis()
317318

318319
if squeeze:
319320
# Discarding unneeded dimensions that equal 1. If we only have one

0 commit comments

Comments
 (0)