def clear_axis(ax: plt.Axes): """Clear all plotted objects on an axis including lines, patches, tests, tables, artists, images, mouseovers, child axes, legends, collections, and containers. See: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_base.py#L1040 Args: ax (plt.Axes): MPL axis to clear """ # ax.clear() # pylint: disable=protected-access ax.lines = [] ax.patches = [] ax.texts = [] ax.tables = [] ax.artists = [] ax.images = [] ax._mouseover_set = _OrderedSet() ax.child_axes = [] ax._current_image = None # strictly for pyplot via _sci, _gci ax.legend_ = None ax.collections = [] # collection.Collection instances ax.containers = [] # reset the bounds for autoscale ax.ignore_existing_data_limits = True