From e89e036fe59903196ff3c52f53c5652499fa4d8b Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 1 Aug 2019 22:45:33 +0200 Subject: [PATCH 1/3] Don't generate individual doc entries for inherited Axes/Axis/Tick methods. These methods directly pass through to the superclass and don't warrant their own page (having a doc page for Tick.add_callback that just reproes the docstring of Artist.add_callback doesn't add much, and may in fact make things more confusing for the reader ("oh, it's separately documented here, perhaps it does something special?"). Also note that the docs for other Artist subclasses (e.g. Line2D, AxesImage, etc.) don't bother repeating these either. --- doc/api/axes_api.rst | 83 +----- doc/api/axis_api.rst | 591 +------------------------------------------ 2 files changed, 7 insertions(+), 667 deletions(-) diff --git a/doc/api/axes_api.rst b/doc/api/axes_api.rst index 4e7e4174ffd3..b4ea5016d526 100644 --- a/doc/api/axes_api.rst +++ b/doc/api/axes_api.rst @@ -14,6 +14,11 @@ :no-members: :no-undoc-members: +Inheritance +=========== +.. inheritance-diagram:: matplotlib.axes.Axes + :private-bases: + The Axes class ============== @@ -574,78 +579,6 @@ Drawing Axes.get_tightbbox -Bulk property manipulation -========================== - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - Axes.set - Axes.update - Axes.properties - Axes.update_from - - -General Artist Properties -========================= - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - Axes.set_agg_filter - Axes.set_alpha - Axes.set_animated - Axes.set_clip_box - Axes.set_clip_on - Axes.set_clip_path - Axes.set_gid - Axes.set_label - Axes.set_path_effects - Axes.set_rasterized - Axes.set_sketch_params - Axes.set_snap - Axes.set_transform - Axes.set_url - Axes.set_visible - Axes.set_zorder - - Axes.get_agg_filter - Axes.get_alpha - Axes.get_animated - Axes.get_clip_box - Axes.get_clip_on - Axes.get_clip_path - Axes.get_gid - Axes.get_label - Axes.get_path_effects - Axes.get_rasterized - Axes.get_sketch_params - Axes.get_snap - Axes.get_transform - Axes.get_url - Axes.get_visible - Axes.get_zorder - - Axes.axes - Axes.set_figure - Axes.get_figure - -Artist Methods -============== - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - Axes.remove - Axes.is_transform_set - - Projection ========== @@ -681,9 +614,3 @@ Other Axes.get_default_bbox_extra_artists Axes.get_transformed_clip_path_and_affine Axes.has_data - - -Inheritance -=========== -.. inheritance-diagram:: matplotlib.axes.Axes - :private-bases: diff --git a/doc/api/axis_api.rst b/doc/api/axis_api.rst index beff96184ec9..499ce229f1cb 100644 --- a/doc/api/axis_api.rst +++ b/doc/api/axis_api.rst @@ -178,6 +178,7 @@ Incremental navigation XAxis Specific -------------- + .. autosummary:: :toctree: _as_gen :template: autosummary.rst @@ -217,6 +218,7 @@ Other Axis.OFFSETTEXTPAD + Axis.axes Axis.limit_range_for_scale Axis.reset_ticks Axis.set_default_intervals @@ -271,592 +273,3 @@ not used together may de-couple your tick labels from your data. Tick.set_label2 Tick.set_pad Tick.update_position - - -Common and inherited methods -============================ - -XTick ------ - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - XTick.apply_tickdir - XTick.get_loc - XTick.get_pad - XTick.get_pad_pixels - XTick.get_tick_padding - XTick.get_tickdir - XTick.get_view_interval - XTick.set_label1 - XTick.set_label2 - XTick.set_pad - XTick.update_position - - - -YTick ------ - - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - YTick.apply_tickdir - YTick.get_loc - YTick.get_pad - YTick.get_pad_pixels - YTick.get_tick_padding - YTick.get_tickdir - YTick.get_view_interval - YTick.set_label1 - YTick.set_label2 - YTick.set_pad - YTick.update_position - -XAxis ------ - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - XAxis.OFFSETTEXTPAD - XAxis.axis_date - XAxis.cla - XAxis.convert_units - XAxis.get_data_interval - XAxis.get_gridlines - XAxis.get_label_position - XAxis.get_label_text - XAxis.get_major_formatter - XAxis.get_major_locator - XAxis.get_major_ticks - XAxis.get_majorticklabels - XAxis.get_majorticklines - XAxis.get_majorticklocs - XAxis.get_minor_formatter - XAxis.get_minor_locator - XAxis.get_minor_ticks - XAxis.get_minorticklabels - XAxis.get_minorticklines - XAxis.get_minorticklocs - XAxis.get_minpos - XAxis.get_offset_text - XAxis.get_pickradius - XAxis.get_scale - XAxis.get_smart_bounds - XAxis.get_tick_padding - XAxis.get_tick_space - XAxis.get_ticklabel_extents - XAxis.get_ticklabels - XAxis.get_ticklines - XAxis.get_ticklocs - XAxis.get_tightbbox - XAxis.get_units - XAxis.get_view_interval - XAxis.grid - XAxis.limit_range_for_scale - XAxis.pan - XAxis.reset_ticks - XAxis.set_data_interval - XAxis.set_default_intervals - XAxis.set_label_coords - XAxis.set_label_position - XAxis.set_label_text - XAxis.set_major_formatter - XAxis.set_major_locator - XAxis.set_minor_formatter - XAxis.set_minor_locator - XAxis.set_pickradius - XAxis.set_smart_bounds - XAxis.set_tick_params - XAxis.set_ticklabels - XAxis.set_ticks - XAxis.set_units - XAxis.set_view_interval - XAxis.update_units - XAxis.zoom - -YAxis ------ - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - YAxis.OFFSETTEXTPAD - YAxis.axis_date - YAxis.cla - YAxis.convert_units - YAxis.get_data_interval - YAxis.get_gridlines - YAxis.get_label_position - YAxis.get_label_text - YAxis.get_major_formatter - YAxis.get_major_locator - YAxis.get_major_ticks - YAxis.get_majorticklabels - YAxis.get_majorticklines - YAxis.get_majorticklocs - YAxis.get_minor_formatter - YAxis.get_minor_locator - YAxis.get_minor_ticks - YAxis.get_minorticklabels - YAxis.get_minorticklines - YAxis.get_minorticklocs - YAxis.get_minpos - YAxis.get_offset_text - YAxis.get_pickradius - YAxis.get_scale - YAxis.get_smart_bounds - YAxis.get_tick_padding - YAxis.get_tick_space - YAxis.get_ticklabel_extents - YAxis.get_ticklabels - YAxis.get_ticklines - YAxis.get_ticklocs - YAxis.get_tightbbox - YAxis.get_units - YAxis.get_view_interval - YAxis.grid - YAxis.limit_range_for_scale - YAxis.pan - YAxis.reset_ticks - YAxis.set_data_interval - YAxis.set_default_intervals - YAxis.set_label_coords - YAxis.set_label_position - YAxis.set_label_text - YAxis.set_major_formatter - YAxis.set_major_locator - YAxis.set_minor_formatter - YAxis.set_minor_locator - YAxis.set_pickradius - YAxis.set_smart_bounds - YAxis.set_tick_params - YAxis.set_ticklabels - YAxis.set_ticks - YAxis.set_units - YAxis.set_view_interval - YAxis.update_units - YAxis.zoom - -Inherited from artist ---------------------- - -Ticks -~~~~~ - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - - Tick.add_callback - Tick.axes - Tick.contains - Tick.convert_xunits - Tick.convert_yunits - Tick.draw - Tick.findobj - Tick.format_cursor_data - Tick.get_agg_filter - Tick.get_alpha - Tick.get_animated - Tick.get_children - Tick.get_clip_box - Tick.get_clip_on - Tick.get_clip_path - Tick.get_contains - Tick.get_cursor_data - Tick.get_figure - Tick.get_gid - Tick.get_label - Tick.get_path_effects - Tick.get_picker - Tick.get_rasterized - Tick.get_sketch_params - Tick.get_snap - Tick.get_transform - Tick.get_transformed_clip_path_and_affine - Tick.get_url - Tick.get_visible - Tick.get_window_extent - Tick.get_zorder - Tick.have_units - Tick.is_transform_set - Tick.mouseover - Tick.pchanged - Tick.pick - Tick.pickable - Tick.properties - Tick.remove - Tick.remove_callback - Tick.set - Tick.set_agg_filter - Tick.set_alpha - Tick.set_animated - Tick.set_clip_box - Tick.set_clip_on - Tick.set_clip_path - Tick.set_contains - Tick.set_figure - Tick.set_gid - Tick.set_label - Tick.set_path_effects - Tick.set_picker - Tick.set_rasterized - Tick.set_sketch_params - Tick.set_snap - Tick.set_transform - Tick.set_url - Tick.set_visible - Tick.set_zorder - Tick.stale - Tick.update - Tick.update_from - Tick.zorder - - XTick.add_callback - XTick.axes - XTick.contains - XTick.convert_xunits - XTick.convert_yunits - XTick.draw - XTick.findobj - XTick.format_cursor_data - XTick.get_agg_filter - XTick.get_alpha - XTick.get_animated - XTick.get_children - XTick.get_clip_box - XTick.get_clip_on - XTick.get_clip_path - XTick.get_contains - XTick.get_cursor_data - XTick.get_figure - XTick.get_gid - XTick.get_label - XTick.get_path_effects - XTick.get_picker - XTick.get_rasterized - XTick.get_sketch_params - XTick.get_snap - XTick.get_transform - XTick.get_transformed_clip_path_and_affine - XTick.get_url - XTick.get_visible - XTick.get_window_extent - XTick.get_zorder - XTick.have_units - XTick.is_transform_set - XTick.mouseover - XTick.pchanged - XTick.pick - XTick.pickable - XTick.properties - XTick.remove - XTick.remove_callback - XTick.set - XTick.set_agg_filter - XTick.set_alpha - XTick.set_animated - XTick.set_clip_box - XTick.set_clip_on - XTick.set_clip_path - XTick.set_contains - XTick.set_figure - XTick.set_gid - XTick.set_label - XTick.set_path_effects - XTick.set_picker - XTick.set_rasterized - XTick.set_sketch_params - XTick.set_snap - XTick.set_transform - XTick.set_url - XTick.set_visible - XTick.set_zorder - XTick.stale - XTick.update - XTick.update_from - XTick.zorder - - YTick.add_callback - YTick.axes - YTick.contains - YTick.convert_xunits - YTick.convert_yunits - YTick.draw - YTick.findobj - YTick.format_cursor_data - YTick.get_agg_filter - YTick.get_alpha - YTick.get_animated - YTick.get_children - YTick.get_clip_box - YTick.get_clip_on - YTick.get_clip_path - YTick.get_contains - YTick.get_cursor_data - YTick.get_figure - YTick.get_gid - YTick.get_label - YTick.get_path_effects - YTick.get_picker - YTick.get_rasterized - YTick.get_sketch_params - YTick.get_snap - YTick.get_transform - YTick.get_transformed_clip_path_and_affine - YTick.get_url - YTick.get_visible - YTick.get_window_extent - YTick.get_zorder - YTick.have_units - YTick.is_transform_set - YTick.mouseover - YTick.pchanged - YTick.pick - YTick.pickable - YTick.properties - YTick.remove - YTick.remove_callback - YTick.set - YTick.set_agg_filter - YTick.set_alpha - YTick.set_animated - YTick.set_clip_box - YTick.set_clip_on - YTick.set_clip_path - YTick.set_contains - YTick.set_figure - YTick.set_gid - YTick.set_label - YTick.set_path_effects - YTick.set_picker - YTick.set_rasterized - YTick.set_sketch_params - YTick.set_snap - YTick.set_transform - YTick.set_url - YTick.set_visible - YTick.set_zorder - YTick.stale - YTick.update - YTick.update_from - YTick.zorder - - -Axis -~~~~ - -.. autosummary:: - :toctree: _as_gen - :template: autosummary.rst - :nosignatures: - - - Axis.add_callback - Axis.axes - Axis.contains - Axis.convert_xunits - Axis.convert_yunits - Axis.draw - Axis.findobj - Axis.format_cursor_data - Axis.get_agg_filter - Axis.get_alpha - Axis.get_animated - Axis.get_children - Axis.get_clip_box - Axis.get_clip_on - Axis.get_clip_path - Axis.get_contains - Axis.get_cursor_data - Axis.get_figure - Axis.get_gid - Axis.get_label - Axis.get_path_effects - Axis.get_picker - Axis.get_rasterized - Axis.get_sketch_params - Axis.get_snap - Axis.get_transform - Axis.get_transformed_clip_path_and_affine - Axis.get_url - Axis.get_visible - Axis.get_window_extent - Axis.get_zorder - Axis.have_units - Axis.is_transform_set - Axis.mouseover - Axis.pchanged - Axis.pick - Axis.pickable - Axis.properties - Axis.remove - Axis.remove_callback - Axis.set - Axis.set_agg_filter - Axis.set_alpha - Axis.set_animated - Axis.set_clip_box - Axis.set_clip_on - Axis.set_clip_path - Axis.set_contains - Axis.set_figure - Axis.set_gid - Axis.set_label - Axis.set_path_effects - Axis.set_picker - Axis.set_rasterized - Axis.set_sketch_params - Axis.set_snap - Axis.set_transform - Axis.set_url - Axis.set_visible - Axis.set_zorder - Axis.stale - Axis.update - Axis.update_from - Axis.zorder - - XAxis.add_callback - XAxis.axes - XAxis.contains - XAxis.convert_xunits - XAxis.convert_yunits - XAxis.draw - XAxis.findobj - XAxis.format_cursor_data - XAxis.get_agg_filter - XAxis.get_alpha - XAxis.get_animated - XAxis.get_children - XAxis.get_clip_box - XAxis.get_clip_on - XAxis.get_clip_path - XAxis.get_contains - XAxis.get_cursor_data - XAxis.get_figure - XAxis.get_gid - XAxis.get_label - XAxis.get_path_effects - XAxis.get_picker - XAxis.get_rasterized - XAxis.get_sketch_params - XAxis.get_snap - XAxis.get_transform - XAxis.get_transformed_clip_path_and_affine - XAxis.get_url - XAxis.get_visible - XAxis.get_window_extent - XAxis.get_zorder - XAxis.have_units - XAxis.is_transform_set - XAxis.mouseover - XAxis.pchanged - XAxis.pick - XAxis.pickable - XAxis.properties - XAxis.remove - XAxis.remove_callback - XAxis.set - XAxis.set_agg_filter - XAxis.set_alpha - XAxis.set_animated - XAxis.set_clip_box - XAxis.set_clip_on - XAxis.set_clip_path - XAxis.set_contains - XAxis.set_figure - XAxis.set_gid - XAxis.set_label - XAxis.set_path_effects - XAxis.set_picker - XAxis.set_rasterized - XAxis.set_sketch_params - XAxis.set_snap - XAxis.set_transform - XAxis.set_url - XAxis.set_visible - XAxis.set_zorder - XAxis.stale - XAxis.update - XAxis.update_from - XAxis.zorder - - YAxis.add_callback - YAxis.axes - YAxis.contains - YAxis.convert_xunits - YAxis.convert_yunits - YAxis.draw - YAxis.findobj - YAxis.format_cursor_data - YAxis.get_agg_filter - YAxis.get_alpha - YAxis.get_animated - YAxis.get_children - YAxis.get_clip_box - YAxis.get_clip_on - YAxis.get_clip_path - YAxis.get_contains - YAxis.get_cursor_data - YAxis.get_figure - YAxis.get_gid - YAxis.get_label - YAxis.get_path_effects - YAxis.get_picker - YAxis.get_rasterized - YAxis.get_sketch_params - YAxis.get_snap - YAxis.get_transform - YAxis.get_transformed_clip_path_and_affine - YAxis.get_url - YAxis.get_visible - YAxis.get_window_extent - YAxis.get_zorder - YAxis.have_units - YAxis.is_transform_set - YAxis.mouseover - YAxis.pchanged - YAxis.pick - YAxis.pickable - YAxis.properties - YAxis.remove - YAxis.remove_callback - YAxis.set - YAxis.set_agg_filter - YAxis.set_alpha - YAxis.set_animated - YAxis.set_clip_box - YAxis.set_clip_on - YAxis.set_clip_path - YAxis.set_contains - YAxis.set_figure - YAxis.set_gid - YAxis.set_label - YAxis.set_path_effects - YAxis.set_picker - YAxis.set_rasterized - YAxis.set_sketch_params - YAxis.set_snap - YAxis.set_transform - YAxis.set_url - YAxis.set_visible - YAxis.set_zorder - YAxis.stale - YAxis.update - YAxis.update_from - YAxis.zorder From 486696488288105e47f8fdb65f73fdb087ad2396 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 13 Aug 2019 01:09:13 +0200 Subject: [PATCH 2/3] 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. --- doc/api/axis_api.rst | 2 +- doc/missing-references.json | 12 ++-- doc/users/prev_whats_new/whats_new_1.5.rst | 6 +- examples/pyplots/align_ylabels.py | 2 +- lib/matplotlib/artist.py | 71 +++++++++++----------- lib/matplotlib/axes/_base.py | 10 +-- tutorials/introductory/lifecycle.py | 3 +- 7 files changed, 49 insertions(+), 57 deletions(-) diff --git a/doc/api/axis_api.rst b/doc/api/axis_api.rst index 499ce229f1cb..c09d646cb0c5 100644 --- a/doc/api/axis_api.rst +++ b/doc/api/axis_api.rst @@ -146,7 +146,7 @@ Interactive :template: autosummary.rst :nosignatures: - + Axis.contains Axis.get_pickradius Axis.set_pickradius diff --git a/doc/missing-references.json b/doc/missing-references.json index d57405c036fe..45873cacb02c 100644 --- a/doc/missing-references.json +++ b/doc/missing-references.json @@ -201,7 +201,7 @@ ], "matplotlib.axes._axes.Axes": [ "doc/api/artist_api.rst:189", - "doc/api/axes_api.rst:686", + "doc/api/axes_api.rst:616", "lib/matplotlib/projections/polar.py:docstring of matplotlib.projections.polar.PolarAxes:1", "lib/mpl_toolkits/axes_grid1/mpl_axes.py:docstring of mpl_toolkits.axes_grid1.mpl_axes.Axes:1", "lib/mpl_toolkits/axisartist/axislines.py:docstring of mpl_toolkits.axisartist.axislines.Axes:1", @@ -209,7 +209,7 @@ ], "matplotlib.axes._base._AxesBase": [ "doc/api/artist_api.rst:189", - "doc/api/axes_api.rst:686", + "doc/api/axes_api.rst:616", "lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes.Axes:1" ], "matplotlib.backend_bases.FigureCanvas": [ @@ -564,7 +564,7 @@ "doc/devel/contributing.rst:562" ], "Artist.sticky_edges": [ - "doc/api/axes_api.rst:357::1", + "doc/api/axes_api.rst:362::1", "lib/matplotlib/axes/_axes.py:docstring of matplotlib.axes.Axes.use_sticky_edges:2" ], "ArtistInspector.aliasd": [ @@ -583,12 +583,12 @@ "doc/users/prev_whats_new/whats_new_3.1.0.rst:247" ], "Axes.dataLim": [ - "doc/api/axes_api.rst:297::1", + "doc/api/axes_api.rst:302::1", "lib/matplotlib/axes/_base.py:docstring of matplotlib.axes.Axes.update_datalim:2", "lib/mpl_toolkits/mplot3d/axes3d.py:docstring of mpl_toolkits.mplot3d.axes3d.Axes3D.update_datalim:2" ], "Axes.datalim": [ - "doc/api/axes_api.rst:297::1", + "doc/api/axes_api.rst:302::1", "lib/matplotlib/axes/_base.py:docstring of matplotlib.axes.Axes.update_datalim_bounds:2" ], "Axes.fmt_xdata": [ @@ -606,7 +606,7 @@ "doc/api/prev_api_changes/api_changes_3.2.0/behavior.rst:96" ], "AxesBase": [ - "doc/api/axes_api.rst:449::1", + "doc/api/axes_api.rst:454::1", "lib/matplotlib/axes/_base.py:docstring of matplotlib.axes.Axes.add_child_axes:2" ], "Axis._update_ticks": [ diff --git a/doc/users/prev_whats_new/whats_new_1.5.rst b/doc/users/prev_whats_new/whats_new_1.5.rst index e62721ecde6d..55f52aa5e417 100644 --- a/doc/users/prev_whats_new/whats_new_1.5.rst +++ b/doc/users/prev_whats_new/whats_new_1.5.rst @@ -509,12 +509,12 @@ which allow artist-level control of LaTeX rendering vs. the internal mathtex rendering. -`.Axes.remove()` works as expected -`````````````````````````````````` +``Axes.remove()`` works as expected +``````````````````````````````````` As with artists added to an :class:`~matplotlib.axes.Axes`, `~.axes.Axes` objects can be removed from their figure via -:meth:`~matplotlib.axes.Axes.remove()`. +`~.Artist.remove()`. API Consistency fix within Locators set_params() function diff --git a/examples/pyplots/align_ylabels.py b/examples/pyplots/align_ylabels.py index d3ef2ced8613..114145f14676 100644 --- a/examples/pyplots/align_ylabels.py +++ b/examples/pyplots/align_ylabels.py @@ -55,7 +55,7 @@ def make_plot(axs): # # # Or we can manually align the axis labels between subplots manually using the -# `~.YAxis.set_label_coords` method of the y-axis object. Note this requires +# `~.Axis.set_label_coords` method of the y-axis object. Note this requires # we know a good offset value which is hardcoded. fig, axs = plt.subplots(2, 2) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index e33561e809f7..ac243019ea7d 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -396,8 +396,8 @@ def _default_contains(self, mouseevent, figure=None): return inside, info # subclass-specific implementation follows - The *figure* kwarg is provided for the implementation of - `Figure.contains`. + The *canvas* kwarg is provided for the implementation of + `.Figure.contains`. """ if callable(self._contains): return self._contains(self, mouseevent) @@ -1304,24 +1304,6 @@ def get_valid_values(self, attr): return 'unknown' - def _get_setters_and_targets(self): - """ - Get the attribute strings and a full path to where the setter - is defined for all setters in an object. - """ - setters = [] - for name in dir(self.o): - if not name.startswith('set_'): - continue - func = getattr(self.o, name) - if (not callable(func) - or len(inspect.signature(func).parameters) < 2 - or self.is_alias(func)): - continue - setters.append( - (name[4:], f"{func.__module__}.{func.__qualname__}")) - return setters - def _replace_path(self, source_class): """ Changes the full path to the public API path that is used @@ -1338,7 +1320,17 @@ def get_setters(self): Get the attribute strings with setters for object. e.g., for a line, return ``['markerfacecolor', 'linewidth', ....]``. """ - return [prop for prop, target in self._get_setters_and_targets()] + setters = [] + for name in dir(self.o): + if not name.startswith('set_'): + continue + func = getattr(self.o, name) + if (not callable(func) + or len(inspect.signature(func).parameters) < 2 + or self.is_alias(func)): + continue + setters.append(name[4:]) + return setters def is_alias(self, o): """Return whether method object *o* is an alias for another method.""" @@ -1387,24 +1379,20 @@ def pprint_setters(self, prop=None, leadingspace=2): accepts = self.get_valid_values(prop) return '%s%s: %s' % (pad, prop, accepts) - attrs = self._get_setters_and_targets() - attrs.sort() lines = [] - - for prop, path in attrs: + for prop in sorted(self.get_setters()): accepts = self.get_valid_values(prop) name = self.aliased_name(prop) - lines.append('%s%s: %s' % (pad, name, accepts)) return lines def pprint_setters_rest(self, prop=None, leadingspace=4): """ - If *prop* is *None*, return a list of strings of all settable - properties and their valid values. Format the output for ReST + If *prop* is *None*, return a list of ReST-formatted strings of all + settable properties and their valid values. If *prop* is not *None*, it is a valid property name and that - property will be returned as a string of property : valid + property will be returned as a string of "property : valid" values. """ if leadingspace: @@ -1415,13 +1403,24 @@ def pprint_setters_rest(self, prop=None, leadingspace=4): accepts = self.get_valid_values(prop) return '%s%s: %s' % (pad, prop, accepts) - attrs = sorted(self._get_setters_and_targets()) - - names = [self.aliased_name_rest(prop, target).replace( - '_base._AxesBase', 'Axes').replace( - '_axes.Axes', 'Axes') - for prop, target in attrs] - accepts = [self.get_valid_values(prop) for prop, target in attrs] + prop_and_qualnames = [] + for prop in sorted(self.get_setters()): + # Find the parent method which actually provides the docstring. + for cls in self.o.__mro__: + method = getattr(cls, f"set_{prop}", None) + if method and method.__doc__ is not None: + break + else: # No docstring available. + method = getattr(self.o, f"set_{prop}") + prop_and_qualnames.append( + (prop, f"{method.__module__}.{method.__qualname__}")) + + names = [self.aliased_name_rest(prop, target) + .replace('_base._AxesBase', 'Axes') + .replace('_axes.Axes', 'Axes') + for prop, target in prop_and_qualnames] + accepts = [self.get_valid_values(prop) + for prop, _ in prop_and_qualnames] col0_len = max(len(n) for n in names) col1_len = max(len(a) for a in accepts) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 5b105e13aeeb..08f69fa46f99 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -621,13 +621,7 @@ def _init_axis(self): self._update_transScale() def set_figure(self, fig): - """ - Set the `.Figure` for this `.Axes`. - - Parameters - ---------- - fig : `.Figure` - """ + # docstring inherited martist.Artist.set_figure(self, fig) self.bbox = mtransforms.TransformedBbox(self._position, @@ -2889,7 +2883,7 @@ def grid(self, b=None, which='major', axis='both', **kwargs): grid is determined by the zorder of each axis, not by the zorder of the `.Line2D` objects comprising the grid. Therefore, to set grid zorder, use `.set_axisbelow` or, for more control, call the - `~matplotlib.axis.Axis.set_zorder` method of each axis. + `~.Artist.set_zorder` method of each axis. """ if len(kwargs): b = True diff --git a/tutorials/introductory/lifecycle.py b/tutorials/introductory/lifecycle.py index 55270a667728..3ef879188c89 100644 --- a/tutorials/introductory/lifecycle.py +++ b/tutorials/introductory/lifecycle.py @@ -157,8 +157,7 @@ ############################################################################### # Next, we'll add labels to the plot. To do this with the OO interface, -# we can use the :meth:`axes.Axes.set` method to set properties of this -# Axes object. +# we can use the `.Artist.set` method to set properties of this Axes object. fig, ax = plt.subplots() ax.barh(group_names, group_data) From 98f10fde1ff08dadbb5b270a23b8ebf39cefae02 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 24 Mar 2020 10:27:45 +0100 Subject: [PATCH 3/3] And some more fixes. --- lib/matplotlib/artist.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index ac243019ea7d..7a20c69bbdbd 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -396,7 +396,7 @@ def _default_contains(self, mouseevent, figure=None): return inside, info # subclass-specific implementation follows - The *canvas* kwarg is provided for the implementation of + The *figure* kwarg is provided for the implementation of `.Figure.contains`. """ if callable(self._contains): @@ -1317,8 +1317,10 @@ def _replace_path(self, source_class): def get_setters(self): """ - Get the attribute strings with setters for object. e.g., for a line, - return ``['markerfacecolor', 'linewidth', ....]``. + Get the attribute strings with setters for object. + + For example, for a line, return ``['markerfacecolor', 'linewidth', + ....]``. """ setters = [] for name in dir(self.o): @@ -1353,7 +1355,7 @@ def aliased_name(self, s): def aliased_name_rest(self, s, target): """ Return 'PROPNAME or alias' if *s* has an alias, else return 'PROPNAME', - formatted for ReST. + formatted for reST. e.g., for the line markerfacecolor property, which has an alias, return 'markerfacecolor or mfc' and for the transform @@ -1388,7 +1390,7 @@ def pprint_setters(self, prop=None, leadingspace=2): def pprint_setters_rest(self, prop=None, leadingspace=4): """ - If *prop* is *None*, return a list of ReST-formatted strings of all + If *prop* is *None*, return a list of reST-formatted strings of all settable properties and their valid values. If *prop* is not *None*, it is a valid property name and that