From f156db08eee54d285ab0fb4e031e48d078ba6aa3 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 27 Jan 2022 23:10:33 +0100 Subject: [PATCH] DOC: More cleanup axes -> Axes --- lib/matplotlib/animation.py | 11 +++++------ lib/matplotlib/artist.py | 12 +++++------- lib/matplotlib/axes/_base.py | 34 ++++++++++++++++----------------- lib/matplotlib/axis.py | 22 ++++++++++----------- lib/matplotlib/backend_bases.py | 31 +++++++++++++++--------------- 5 files changed, 54 insertions(+), 56 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 7909d11352b7..3ae4233312bc 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1161,11 +1161,11 @@ def _blit_draw(self, artists): # Handles blitted drawing, which renders only the artists given instead # of the entire figure. updated_ax = {a.axes for a in artists} - # Enumerate artists to cache axes' backgrounds. We do not draw + # Enumerate artists to cache Axes backgrounds. We do not draw # artists yet to not cache foreground from plots with shared axes for ax in updated_ax: # If we haven't cached the background for the current view of this - # axes object, do so now. This might not always be reliable, but + # Axes object, do so now. This might not always be reliable, but # it's an attempt to automate the process. cur_view = ax._get_view() view, bg = self._blit_cache.get(ax, (object(), None)) @@ -1175,12 +1175,12 @@ def _blit_draw(self, artists): # Make a separate pass to draw foreground. for a in artists: a.axes.draw_artist(a) - # After rendering all the needed artists, blit each axes individually. + # After rendering all the needed artists, blit each Axes individually. for ax in updated_ax: ax.figure.canvas.blit(ax.bbox) def _blit_clear(self, artists): - # Get a list of the axes that need clearing from the artists that + # Get a list of the Axes that need clearing from the artists that # have been drawn. Grab the appropriate saved background from the # cache and restore. axes = {a.axes for a in artists} @@ -1195,8 +1195,7 @@ def _blit_clear(self, artists): self._blit_cache.pop(ax) def _setup_blit(self): - # Setting up the blit requires: a cache of the background for the - # axes + # Setting up the blit requires: a cache of the background for the Axes self._blit_cache = dict() self._drawn_artists = [] self._resize_id = self._fig.canvas.mpl_connect('resize_event', diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 06f418cf7404..f0f4ed9be89a 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -215,10 +215,8 @@ def remove(self): if hasattr(self, 'axes') and self.axes: # remove from the mouse hit list self.axes._mouseover_set.discard(self) - # mark the axes as stale self.axes.stale = True - # decouple the artist from the axes - self.axes = None + self.axes = None # decouple the artist from the Axes _ax_flag = True if self.figure: @@ -511,14 +509,14 @@ def pick(self, mouseevent): # Pick children for a in self.get_children(): - # make sure the event happened in the same axes + # make sure the event happened in the same Axes ax = getattr(a, 'axes', None) if (mouseevent.inaxes is None or ax is None or mouseevent.inaxes == ax): # we need to check if mouseevent.inaxes is None # because some objects associated with an Axes (e.g., a # tick label) can be outside the bounding box of the - # axes and inaxes will be None + # Axes and inaxes will be None # also check that ax is None so that it traverse objects # which do no have an axes property but children might a.pick(mouseevent) @@ -829,7 +827,7 @@ def get_in_layout(self): def _fully_clipped_to_axes(self): """ - Return a boolean flag, ``True`` if the artist is clipped to the axes + Return a boolean flag, ``True`` if the artist is clipped to the Axes and can thus be skipped in layout calculations. Requires `get_clip_on` is True, one of `clip_box` or `clip_path` is set, ``clip_box.extents`` is equivalent to ``ax.bbox.extents`` (if set), and ``clip_path._patch`` @@ -877,7 +875,7 @@ def set_clip_on(self, b): """ Set whether the artist uses clipping. - When False artists will be visible outside of the axes which + When False artists will be visible outside of the Axes which can lead to unexpected results. Parameters diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e7c800462d99..96309d613921 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -99,7 +99,7 @@ class _TransformedBoundsLocator: Axes locator for `.Axes.inset_axes` and similarly positioned Axes. The locator is a callable object used in `.Axes.set_aspect` to compute the - axes location depending on the renderer. + Axes location depending on the renderer. """ def __init__(self, bounds, transform): @@ -1117,7 +1117,7 @@ def _gen_axes_patch(self): The patch used to draw the background of the Axes. It is also used as the clipping path for any data elements on the Axes. - In the standard axes, this is a rectangle, but in other projections + In the standard Axes, this is a rectangle, but in other projections it may not be. Notes @@ -1149,7 +1149,7 @@ def sharex(self, other): Share the x-axis with *other*. This is equivalent to passing ``sharex=other`` when constructing the - axes, and cannot be used if the x-axis is already being shared with + Axes, and cannot be used if the x-axis is already being shared with another Axes. """ _api.check_isinstance(_AxesBase, other=other) @@ -1168,7 +1168,7 @@ def sharey(self, other): Share the y-axis with *other*. This is equivalent to passing ``sharey=other`` when constructing the - axes, and cannot be used if the y-axis is already being shared with + Axes, and cannot be used if the y-axis is already being shared with another Axes. """ _api.check_isinstance(_AxesBase, other=other) @@ -2413,7 +2413,7 @@ def add_table(self, tab): def add_container(self, container): """ - Add a `.Container` to the axes' containers; return the container. + Add a `.Container` to the Axes' containers; return the container. """ label = container.get_label() if not label: @@ -2499,8 +2499,8 @@ def _process_unit_info(self, datasets=None, kwargs=None, *, convert=True): (which gets passed through). kwargs : dict Other parameters from which unit info (i.e., the *xunits*, - *yunits*, *zunits* (for 3D axes), *runits* and *thetaunits* (for - polar axes) entries) is popped, if present. Note that this dict is + *yunits*, *zunits* (for 3D Axes), *runits* and *thetaunits* (for + polar) entries) is popped, if present. Note that this dict is mutated in-place! convert : bool, default: True Whether to return the original datasets or the converted ones. @@ -2779,7 +2779,7 @@ def autoscale(self, enable=True, axis='both', tight=None): True turns autoscaling on, False turns it off. None leaves the autoscaling state unchanged. axis : {'both', 'x', 'y'}, default: 'both' - The axis on which to operate. (For 3D axes, *axis* can also be set + The axis on which to operate. (For 3D Axes, *axis* can also be set to 'z', and 'both' refers to all three axes.) tight : bool or None, default: None If True, first set the margins to zero. Then, this argument is @@ -2853,7 +2853,7 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True): if self.use_sticky_edges: # Only iterate over Axes and artists if needed. The check for # ``hasattr(ax, "_children")`` is necessary because this can be - # called very early in the Axes init process (e.g., for twin axes) + # called very early in the Axes init process (e.g., for twin Axes) # when these attributes don't even exist yet, in which case # `get_children` would raise an AttributeError. if self._xmargin and scalex and self._autoscaleXon: @@ -2953,7 +2953,7 @@ def _get_axis_map(self): Return a mapping of `Axis` "names" to `Axis` instances. The `Axis` name is derived from the attribute under which the instance - is stored, so e.g. for polar axes, the theta-axis is still named "x" + is stored, so e.g. for polar Axes, the theta-axis is still named "x" and the r-axis is still named "y" (for back-compatibility). In practice, this means that the entries are typically "x" and "y", and @@ -3245,7 +3245,7 @@ def grid(self, visible=None, which='major', axis='both', **kwargs): def ticklabel_format(self, *, axis='both', style='', scilimits=None, useOffset=None, useLocale=None, useMathText=None): r""" - Configure the `.ScalarFormatter` used by default for linear axes. + Configure the `.ScalarFormatter` used by default for linear Axes. If a parameter is not set, the corresponding property of the formatter is left unchanged. @@ -3327,7 +3327,7 @@ def locator_params(self, axis='both', tight=None, **kwargs): Parameters ---------- axis : {'both', 'x', 'y'}, default: 'both' - The axis on which to operate. (For 3D axes, *axis* can also be + The axis on which to operate. (For 3D Axes, *axis* can also be set to 'z', and 'both' refers to all three axes.) tight : bool or None, optional Parameter passed to `~.Axes.autoscale_view`. @@ -3340,7 +3340,7 @@ def locator_params(self, axis='both', tight=None, **kwargs): ``set_params()`` method of the locator. Supported keywords depend on the type of the locator. See for example `~.ticker.MaxNLocator.set_params` for the `.ticker.MaxNLocator` - used by default for linear axes. + used by default for linear. Examples -------- @@ -3377,7 +3377,7 @@ def tick_params(self, axis='both', **kwargs): Other Parameters ---------------- direction : {'in', 'out', 'inout'} - Puts ticks inside the axes, outside the axes, or both. + Puts ticks inside the Axes, outside the Axes, or both. length : float Tick length in points. width : float @@ -4538,7 +4538,7 @@ def contains(self, mouseevent): def contains_point(self, point): """ - Return whether *point* (pair of pixel coordinates) is inside the axes + Return whether *point* (pair of pixel coordinates) is inside the Axes patch. """ return self.patch.contains_point(point, radius=1.0) @@ -4568,7 +4568,7 @@ def get_default_bbox_extra_artists(self): artists.remove(self._right_title) # always include types that do not internally implement clipping - # to axes. may have clip_on set to True and clip_box equivalent + # to Axes. may have clip_on set to True and clip_box equivalent # to ax.bbox but then ignore these properties during draws. noclip = (_AxesBase, maxis.Axis, offsetbox.AnnotationBbox, offsetbox.OffsetBox) @@ -4578,7 +4578,7 @@ def get_default_bbox_extra_artists(self): def get_tightbbox(self, renderer, call_axes_locator=True, bbox_extra_artists=None, *, for_layout_only=False): """ - Return the tight bounding box of the axes, including axis and their + Return the tight bounding box of the Axes, including axis and their decorators (xlabel, title, etc). Artists that have ``artist.set_in_layout(False)`` are not included diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 5782918e17b8..5f3f07c54dac 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -220,7 +220,7 @@ def get_tickdir(self): return self._tickdir def get_tick_padding(self): - """Get the length of the tick outside of the axes.""" + """Get the length of the tick outside of the Axes.""" padding = { 'in': 0.0, 'inout': 0.5, @@ -1869,7 +1869,7 @@ def _get_tick_boxes_siblings(self, renderer): grouper = self.figure._align_label_groups[axis_name] bboxes = [] bboxes2 = [] - # If we want to align labels from other axes: + # If we want to align labels from other Axes: for ax in grouper.get_siblings(self.axes): axis = getattr(ax, f"{axis_name}axis") ticks_to_draw = axis._update_ticks() @@ -2083,7 +2083,7 @@ def _update_label_position(self, renderer): spine = self.axes.spines['bottom'] spinebbox = spine.get_window_extent() except KeyError: - # use axes if spine doesn't exist + # use Axes if spine doesn't exist spinebbox = self.axes.bbox bbox = mtransforms.Bbox.union(bboxes + [spinebbox]) bottom = bbox.y0 @@ -2096,7 +2096,7 @@ def _update_label_position(self, renderer): spine = self.axes.spines['top'] spinebbox = spine.get_window_extent() except KeyError: - # use axes if spine doesn't exist + # use Axes if spine doesn't exist spinebbox = self.axes.bbox bbox = mtransforms.Bbox.union(bboxes2 + [spinebbox]) top = bbox.y1 @@ -2132,7 +2132,7 @@ def _update_offset_text_position(self, bboxes, bboxes2): def get_text_heights(self, renderer): """ Return how much space should be reserved for text above and below the - axes, as a pair of floats. + Axes, as a pair of floats. """ bbox, bbox2 = self.get_ticklabel_extents(renderer) # MGDTODO: Need a better way to get the pad @@ -2193,7 +2193,7 @@ def set_ticks_position(self, position): def tick_top(self): """ - Move ticks and ticklabels (if present) to the top of the axes. + Move ticks and ticklabels (if present) to the top of the Axes. """ label = True if 'label1On' in self._major_tick_kw: @@ -2205,7 +2205,7 @@ def tick_top(self): def tick_bottom(self): """ - Move ticks and ticklabels (if present) to the bottom of the axes. + Move ticks and ticklabels (if present) to the bottom of the Axes. """ label = True if 'label1On' in self._major_tick_kw: @@ -2347,7 +2347,7 @@ def _update_label_position(self, renderer): spine = self.axes.spines['left'] spinebbox = spine.get_window_extent() except KeyError: - # use axes if spine doesn't exist + # use Axes if spine doesn't exist spinebbox = self.axes.bbox bbox = mtransforms.Bbox.union(bboxes + [spinebbox]) left = bbox.x0 @@ -2360,7 +2360,7 @@ def _update_label_position(self, renderer): spine = self.axes.spines['right'] spinebbox = spine.get_window_extent() except KeyError: - # use axes if spine doesn't exist + # use Axes if spine doesn't exist spinebbox = self.axes.bbox bbox = mtransforms.Bbox.union(bboxes2 + [spinebbox]) @@ -2449,7 +2449,7 @@ def set_ticks_position(self, position): def tick_right(self): """ - Move ticks and ticklabels (if present) to the right of the axes. + Move ticks and ticklabels (if present) to the right of the Axes. """ label = True if 'label1On' in self._major_tick_kw: @@ -2462,7 +2462,7 @@ def tick_right(self): def tick_left(self): """ - Move ticks and ticklabels (if present) to the left of the axes. + Move ticks and ticklabels (if present) to the left of the Axes. """ label = True if 'label1On' in self._major_tick_kw: diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 8aefafed5ccb..0c7893b81977 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1301,12 +1301,12 @@ def __init__(self, name, canvas, x, y, guiEvent=None): self.x = int(x) if x is not None else x # y position - pixels from right of canvas self.y = int(y) if y is not None else y - self.inaxes = None # the Axes instance if mouse us over axes + self.inaxes = None # the Axes instance the mouse is over self.xdata = None # x coord of mouse in data coords self.ydata = None # y coord of mouse in data coords if x is None or y is None: - # cannot check if event was in axes if no (x, y) info + # cannot check if event was in Axes if no (x, y) info self._update_enter_leave() return @@ -1332,7 +1332,7 @@ def _update_enter_leave(self): if LocationEvent.lastevent is not None: last = LocationEvent.lastevent if last.inaxes != self.inaxes: - # process axes enter/leave events + # process Axes enter/leave events try: if last.inaxes is not None: last.canvas.callbacks.process('axes_leave_event', last) @@ -1619,7 +1619,7 @@ def __init__(self, figure=None): self._button = None # the button pressed self._key = None # the key pressed self._lastx, self._lasty = None, None - self.mouse_grabber = None # the axes currently grabbing mouse + self.mouse_grabber = None # the Axes currently grabbing mouse self.toolbar = None # NavigationToolbar2 will set me self._is_idle_drawing = False # We don't want to scale up the figure DPI more than once. @@ -1901,7 +1901,8 @@ def inaxes(self, xy): Returns ------- `~matplotlib.axes.Axes` or None - The topmost visible axes containing the point, or None if no axes. + The topmost visible Axes containing the point, or None if there + is no Axes at the point. """ axes_list = [a for a in self.figure.get_axes() if a.patch.contains_point(xy) and a.get_visible()] @@ -1917,7 +1918,7 @@ def grab_mouse(self, ax): Set the child `~.axes.Axes` which is grabbing the mouse events. Usually called by the widgets themselves. It is an error to call this - if the mouse is already grabbed by another axes. + if the mouse is already grabbed by another Axes. """ if self.mouse_grabber not in (None, ax): raise RuntimeError("Another Axes already grabs mouse input") @@ -2360,7 +2361,7 @@ def mpl_connect(self, s, func): def func(event: Event) -> Any For the location events (button and key press/release), if the - mouse is over the axes, the ``inaxes`` attribute of the event will + mouse is over the Axes, the ``inaxes`` attribute of the event will be set to the `~matplotlib.axes.Axes` the event occurs is over, and additionally, the variables ``xdata`` and ``ydata`` attributes will be set to the mouse location in data coordinates. See `.KeyEvent` @@ -2565,7 +2566,7 @@ def _get_uniform_gridstate(ticks): return None ax = event.inaxes - # toggle major grids in current axes (default key 'g') + # toggle major grids in current Axes (default key 'g') # Both here and below (for 'G'), we do nothing if *any* grid (major or # minor, x or y) is not in a uniform state, to avoid messing up user # customization. @@ -2587,7 +2588,7 @@ def _get_uniform_gridstate(ticks): ax.grid(x_state, which="major" if x_state else "both", axis="x") ax.grid(y_state, which="major" if y_state else "both", axis="y") canvas.draw_idle() - # toggle major and minor grids in current axes (default key 'G') + # toggle major and minor grids in current Axes (default key 'G') if (event.key in grid_minor_keys # Exclude major grids not in a uniform state. and None not in [_get_uniform_gridstate(ax.xaxis.majorTicks), @@ -2752,7 +2753,7 @@ def __init__(self, canvas, num): @self.canvas.figure.add_axobserver def notify_axes_change(fig): - # Called whenever the current axes is changed. + # Called whenever the current Axes is changed. if self.toolmanager is None and self.toolbar is not None: self.toolbar.update() @@ -3119,7 +3120,7 @@ def press_zoom(self, event): id_zoom = self.canvas.mpl_connect( "motion_notify_event", self.drag_zoom) # A colorbar is one-dimensional, so we extend the zoom rectangle out - # to the edge of the axes bbox in the other dimension. To do that we + # to the edge of the Axes bbox in the other dimension. To do that we # store the orientation of the colorbar for later. if hasattr(axes[0], "_colorbar"): cbar = axes[0]._colorbar.orientation @@ -3175,8 +3176,8 @@ def release_zoom(self, event): return for i, ax in enumerate(self._zoom_info.axes): - # Detect whether this axes is twinned with an earlier axes in the - # list of zoomed axes, to avoid double zooming. + # Detect whether this Axes is twinned with an earlier Axes in the + # list of zoomed Axes, to avoid double zooming. twinx = any(ax.get_shared_x_axes().joined(ax, prev) for prev in self._zoom_info.axes[:i]) twiny = any(ax.get_shared_y_axes().joined(ax, prev) @@ -3203,7 +3204,7 @@ def push_current(self): def _update_view(self): """ Update the viewlim and position from the view and position stack for - each axes. + each Axes. """ nav_info = self._nav_stack() if nav_info is None: @@ -3255,7 +3256,7 @@ def set_cursor(self, cursor): self.canvas.set_cursor(cursor) def update(self): - """Reset the axes stack.""" + """Reset the Axes stack.""" self._nav_stack.clear() self.set_history_buttons()