Skip to content

Commit 4866964

Browse files
committed
Fix broken references.
In particular, the property table for artists was changed to point links to the parent method which actually provides the docstring, if the docstring is inherited.
1 parent e89e036 commit 4866964

File tree

7 files changed

+49
-57
lines changed

7 files changed

+49
-57
lines changed

doc/api/axis_api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Interactive
146146
:template: autosummary.rst
147147
:nosignatures:
148148

149-
149+
Axis.contains
150150
Axis.get_pickradius
151151
Axis.set_pickradius
152152

doc/missing-references.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@
201201
],
202202
"matplotlib.axes._axes.Axes": [
203203
"doc/api/artist_api.rst:189",
204-
"doc/api/axes_api.rst:686",
204+
"doc/api/axes_api.rst:616",
205205
"lib/matplotlib/projections/polar.py:docstring of matplotlib.projections.polar.PolarAxes:1",
206206
"lib/mpl_toolkits/axes_grid1/mpl_axes.py:docstring of mpl_toolkits.axes_grid1.mpl_axes.Axes:1",
207207
"lib/mpl_toolkits/axisartist/axislines.py:docstring of mpl_toolkits.axisartist.axislines.Axes:1",
208208
"lib/mpl_toolkits/mplot3d/axes3d.py:docstring of mpl_toolkits.mplot3d.axes3d.Axes3D:1"
209209
],
210210
"matplotlib.axes._base._AxesBase": [
211211
"doc/api/artist_api.rst:189",
212-
"doc/api/axes_api.rst:686",
212+
"doc/api/axes_api.rst:616",
213213
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes.Axes:1"
214214
],
215215
"matplotlib.backend_bases.FigureCanvas": [
@@ -564,7 +564,7 @@
564564
"doc/devel/contributing.rst:562"
565565
],
566566
"Artist.sticky_edges": [
567-
"doc/api/axes_api.rst:357:<autosummary>:1",
567+
"doc/api/axes_api.rst:362:<autosummary>:1",
568568
"lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes.Axes.use_sticky_edges:2"
569569
],
570570
"ArtistInspector.aliasd": [
@@ -583,12 +583,12 @@
583583
"doc/users/prev_whats_new/whats_new_3.1.0.rst:247"
584584
],
585585
"Axes.dataLim": [
586-
"doc/api/axes_api.rst:297:<autosummary>:1",
586+
"doc/api/axes_api.rst:302:<autosummary>:1",
587587
"lib/matplotlib/axes/_base.py:docstring of matplotlib.axes.Axes.update_datalim:2",
588588
"lib/mpl_toolkits/mplot3d/axes3d.py:docstring of mpl_toolkits.mplot3d.axes3d.Axes3D.update_datalim:2"
589589
],
590590
"Axes.datalim": [
591-
"doc/api/axes_api.rst:297:<autosummary>:1",
591+
"doc/api/axes_api.rst:302:<autosummary>:1",
592592
"lib/matplotlib/axes/_base.py:docstring of matplotlib.axes.Axes.update_datalim_bounds:2"
593593
],
594594
"Axes.fmt_xdata": [
@@ -606,7 +606,7 @@
606606
"doc/api/prev_api_changes/api_changes_3.2.0/behavior.rst:96"
607607
],
608608
"AxesBase": [
609-
"doc/api/axes_api.rst:449:<autosummary>:1",
609+
"doc/api/axes_api.rst:454:<autosummary>:1",
610610
"lib/matplotlib/axes/_base.py:docstring of matplotlib.axes.Axes.add_child_axes:2"
611611
],
612612
"Axis._update_ticks": [

doc/users/prev_whats_new/whats_new_1.5.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,12 @@ which allow artist-level control of LaTeX rendering vs. the internal mathtex
509509
rendering.
510510

511511

512-
`.Axes.remove()` works as expected
513-
``````````````````````````````````
512+
``Axes.remove()`` works as expected
513+
```````````````````````````````````
514514

515515
As with artists added to an :class:`~matplotlib.axes.Axes`,
516516
`~.axes.Axes` objects can be removed from their figure via
517-
:meth:`~matplotlib.axes.Axes.remove()`.
517+
`~.Artist.remove()`.
518518

519519

520520
API Consistency fix within Locators set_params() function

examples/pyplots/align_ylabels.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def make_plot(axs):
5555
#
5656
#
5757
# Or we can manually align the axis labels between subplots manually using the
58-
# `~.YAxis.set_label_coords` method of the y-axis object. Note this requires
58+
# `~.Axis.set_label_coords` method of the y-axis object. Note this requires
5959
# we know a good offset value which is hardcoded.
6060

6161
fig, axs = plt.subplots(2, 2)

lib/matplotlib/artist.py

+35-36
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ def _default_contains(self, mouseevent, figure=None):
396396
return inside, info
397397
# subclass-specific implementation follows
398398
399-
The *figure* kwarg is provided for the implementation of
400-
`Figure.contains`.
399+
The *canvas* kwarg is provided for the implementation of
400+
`.Figure.contains`.
401401
"""
402402
if callable(self._contains):
403403
return self._contains(self, mouseevent)
@@ -1304,24 +1304,6 @@ def get_valid_values(self, attr):
13041304

13051305
return 'unknown'
13061306

1307-
def _get_setters_and_targets(self):
1308-
"""
1309-
Get the attribute strings and a full path to where the setter
1310-
is defined for all setters in an object.
1311-
"""
1312-
setters = []
1313-
for name in dir(self.o):
1314-
if not name.startswith('set_'):
1315-
continue
1316-
func = getattr(self.o, name)
1317-
if (not callable(func)
1318-
or len(inspect.signature(func).parameters) < 2
1319-
or self.is_alias(func)):
1320-
continue
1321-
setters.append(
1322-
(name[4:], f"{func.__module__}.{func.__qualname__}"))
1323-
return setters
1324-
13251307
def _replace_path(self, source_class):
13261308
"""
13271309
Changes the full path to the public API path that is used
@@ -1338,7 +1320,17 @@ def get_setters(self):
13381320
Get the attribute strings with setters for object. e.g., for a line,
13391321
return ``['markerfacecolor', 'linewidth', ....]``.
13401322
"""
1341-
return [prop for prop, target in self._get_setters_and_targets()]
1323+
setters = []
1324+
for name in dir(self.o):
1325+
if not name.startswith('set_'):
1326+
continue
1327+
func = getattr(self.o, name)
1328+
if (not callable(func)
1329+
or len(inspect.signature(func).parameters) < 2
1330+
or self.is_alias(func)):
1331+
continue
1332+
setters.append(name[4:])
1333+
return setters
13421334

13431335
def is_alias(self, o):
13441336
"""Return whether method object *o* is an alias for another method."""
@@ -1387,24 +1379,20 @@ def pprint_setters(self, prop=None, leadingspace=2):
13871379
accepts = self.get_valid_values(prop)
13881380
return '%s%s: %s' % (pad, prop, accepts)
13891381

1390-
attrs = self._get_setters_and_targets()
1391-
attrs.sort()
13921382
lines = []
1393-
1394-
for prop, path in attrs:
1383+
for prop in sorted(self.get_setters()):
13951384
accepts = self.get_valid_values(prop)
13961385
name = self.aliased_name(prop)
1397-
13981386
lines.append('%s%s: %s' % (pad, name, accepts))
13991387
return lines
14001388

14011389
def pprint_setters_rest(self, prop=None, leadingspace=4):
14021390
"""
1403-
If *prop* is *None*, return a list of strings of all settable
1404-
properties and their valid values. Format the output for ReST
1391+
If *prop* is *None*, return a list of ReST-formatted strings of all
1392+
settable properties and their valid values.
14051393
14061394
If *prop* is not *None*, it is a valid property name and that
1407-
property will be returned as a string of property : valid
1395+
property will be returned as a string of "property : valid"
14081396
values.
14091397
"""
14101398
if leadingspace:
@@ -1415,13 +1403,24 @@ def pprint_setters_rest(self, prop=None, leadingspace=4):
14151403
accepts = self.get_valid_values(prop)
14161404
return '%s%s: %s' % (pad, prop, accepts)
14171405

1418-
attrs = sorted(self._get_setters_and_targets())
1419-
1420-
names = [self.aliased_name_rest(prop, target).replace(
1421-
'_base._AxesBase', 'Axes').replace(
1422-
'_axes.Axes', 'Axes')
1423-
for prop, target in attrs]
1424-
accepts = [self.get_valid_values(prop) for prop, target in attrs]
1406+
prop_and_qualnames = []
1407+
for prop in sorted(self.get_setters()):
1408+
# Find the parent method which actually provides the docstring.
1409+
for cls in self.o.__mro__:
1410+
method = getattr(cls, f"set_{prop}", None)
1411+
if method and method.__doc__ is not None:
1412+
break
1413+
else: # No docstring available.
1414+
method = getattr(self.o, f"set_{prop}")
1415+
prop_and_qualnames.append(
1416+
(prop, f"{method.__module__}.{method.__qualname__}"))
1417+
1418+
names = [self.aliased_name_rest(prop, target)
1419+
.replace('_base._AxesBase', 'Axes')
1420+
.replace('_axes.Axes', 'Axes')
1421+
for prop, target in prop_and_qualnames]
1422+
accepts = [self.get_valid_values(prop)
1423+
for prop, _ in prop_and_qualnames]
14251424

14261425
col0_len = max(len(n) for n in names)
14271426
col1_len = max(len(a) for a in accepts)

lib/matplotlib/axes/_base.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,7 @@ def _init_axis(self):
621621
self._update_transScale()
622622

623623
def set_figure(self, fig):
624-
"""
625-
Set the `.Figure` for this `.Axes`.
626-
627-
Parameters
628-
----------
629-
fig : `.Figure`
630-
"""
624+
# docstring inherited
631625
martist.Artist.set_figure(self, fig)
632626

633627
self.bbox = mtransforms.TransformedBbox(self._position,
@@ -2889,7 +2883,7 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
28892883
grid is determined by the zorder of each axis, not by the zorder of the
28902884
`.Line2D` objects comprising the grid. Therefore, to set grid zorder,
28912885
use `.set_axisbelow` or, for more control, call the
2892-
`~matplotlib.axis.Axis.set_zorder` method of each axis.
2886+
`~.Artist.set_zorder` method of each axis.
28932887
"""
28942888
if len(kwargs):
28952889
b = True

tutorials/introductory/lifecycle.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@
157157

158158
###############################################################################
159159
# Next, we'll add labels to the plot. To do this with the OO interface,
160-
# we can use the :meth:`axes.Axes.set` method to set properties of this
161-
# Axes object.
160+
# we can use the `.Artist.set` method to set properties of this Axes object.
162161

163162
fig, ax = plt.subplots()
164163
ax.barh(group_names, group_data)

0 commit comments

Comments
 (0)