Skip to content

Commit bc18ac4

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 3d9fde4 commit bc18ac4

File tree

6 files changed

+43
-51
lines changed

6 files changed

+43
-51
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/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
@@ -393,8 +393,8 @@ def _default_contains(self, mouseevent, figure=None):
393393
return inside, info
394394
# subclass-specific implementation follows
395395
396-
The `canvas` kwarg is provided for the implementation of
397-
`Figure.contains`.
396+
The *canvas* kwarg is provided for the implementation of
397+
`.Figure.contains`.
398398
"""
399399
if callable(self._contains):
400400
return self._contains(self, mouseevent)
@@ -1293,24 +1293,6 @@ def get_valid_values(self, attr):
12931293

12941294
return 'unknown'
12951295

1296-
def _get_setters_and_targets(self):
1297-
"""
1298-
Get the attribute strings and a full path to where the setter
1299-
is defined for all setters in an object.
1300-
"""
1301-
setters = []
1302-
for name in dir(self.o):
1303-
if not name.startswith('set_'):
1304-
continue
1305-
func = getattr(self.o, name)
1306-
if (not callable(func)
1307-
or len(inspect.signature(func).parameters) < 2
1308-
or self.is_alias(func)):
1309-
continue
1310-
setters.append(
1311-
(name[4:], f"{func.__module__}.{func.__qualname__}"))
1312-
return setters
1313-
13141296
def _replace_path(self, source_class):
13151297
"""
13161298
Changes the full path to the public API path that is used
@@ -1327,7 +1309,17 @@ def get_setters(self):
13271309
Get the attribute strings with setters for object. e.g., for a line,
13281310
return ``['markerfacecolor', 'linewidth', ....]``.
13291311
"""
1330-
return [prop for prop, target in self._get_setters_and_targets()]
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(name[4:])
1322+
return setters
13311323

13321324
def is_alias(self, o):
13331325
"""Return whether method object *o* is an alias for another method."""
@@ -1376,24 +1368,20 @@ def pprint_setters(self, prop=None, leadingspace=2):
13761368
accepts = self.get_valid_values(prop)
13771369
return '%s%s: %s' % (pad, prop, accepts)
13781370

1379-
attrs = self._get_setters_and_targets()
1380-
attrs.sort()
13811371
lines = []
1382-
1383-
for prop, path in attrs:
1372+
for prop in sorted(self.get_setters()):
13841373
accepts = self.get_valid_values(prop)
13851374
name = self.aliased_name(prop)
1386-
13871375
lines.append('%s%s: %s' % (pad, name, accepts))
13881376
return lines
13891377

13901378
def pprint_setters_rest(self, prop=None, leadingspace=4):
13911379
"""
1392-
If *prop* is *None*, return a list of strings of all settable
1393-
properties and their valid values. Format the output for ReST
1380+
If *prop* is *None*, return a list of ReST-formatted strings of all
1381+
settable properties and their valid values.
13941382
13951383
If *prop* is not *None*, it is a valid property name and that
1396-
property will be returned as a string of property : valid
1384+
property will be returned as a string of "property : valid"
13971385
values.
13981386
"""
13991387
if leadingspace:
@@ -1404,13 +1392,24 @@ def pprint_setters_rest(self, prop=None, leadingspace=4):
14041392
accepts = self.get_valid_values(prop)
14051393
return '%s%s: %s' % (pad, prop, accepts)
14061394

1407-
attrs = sorted(self._get_setters_and_targets())
1408-
1409-
names = [self.aliased_name_rest(prop, target).replace(
1410-
'_base._AxesBase', 'Axes').replace(
1411-
'_axes.Axes', 'Axes')
1412-
for prop, target in attrs]
1413-
accepts = [self.get_valid_values(prop) for prop, target in attrs]
1395+
prop_and_qualnames = []
1396+
for prop in sorted(self.get_setters()):
1397+
# Find the parent method which actually provides the docstring.
1398+
for cls in self.o.__mro__:
1399+
method = getattr(cls, f"set_{prop}", None)
1400+
if method and method.__doc__ is not None:
1401+
break
1402+
else: # No docstring available.
1403+
method = getattr(self.o, f"set_{prop}")
1404+
prop_and_qualnames.append(
1405+
(prop, f"{method.__module__}.{method.__qualname__}"))
1406+
1407+
names = [self.aliased_name_rest(prop, target)
1408+
.replace('_base._AxesBase', 'Axes')
1409+
.replace('_axes.Axes', 'Axes')
1410+
for prop, target in prop_and_qualnames]
1411+
accepts = [self.get_valid_values(prop)
1412+
for prop, _ in prop_and_qualnames]
14141413

14151414
col0_len = max(len(n) for n in names)
14161415
col1_len = max(len(a) for a in accepts)

lib/matplotlib/axes/_base.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,7 @@ def _init_axis(self):
568568
self._update_transScale()
569569

570570
def set_figure(self, fig):
571-
"""
572-
Set the `.Figure` for this `.Axes`.
573-
574-
Parameters
575-
----------
576-
fig : `.Figure`
577-
"""
571+
# docstring inherited
578572
martist.Artist.set_figure(self, fig)
579573

580574
self.bbox = mtransforms.TransformedBbox(self._position,
@@ -2813,7 +2807,7 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
28132807
grid is determined by the zorder of each axis, not by the zorder of the
28142808
`.Line2D` objects comprising the grid. Therefore, to set grid zorder,
28152809
use `.set_axisbelow` or, for more control, call the
2816-
`~matplotlib.axis.Axis.set_zorder` method of each axis.
2810+
`~.Artist.set_zorder` method of each axis.
28172811
"""
28182812
if len(kwargs):
28192813
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)