Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove 3.3 ticker deprecations #20095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions doc/api/axis_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,6 @@ Units
Axis.update_units


Incremental navigation
----------------------

.. autosummary::
:toctree: _as_gen
:template: autosummary.rst
:nosignatures:

Axis.pan
Axis.zoom

XAxis Specific
--------------

Expand Down
20 changes: 20 additions & 0 deletions doc/api/next_api_changes/removals/20095-ES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Axis and Locator ``pan`` and ``zoom``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The unused ``pan`` and ``zoom`` methods of `~.axis.Axis` and `~.ticker.Locator`
have been removed. Panning and zooming are now implemented using the
``start_pan``, ``drag_pan``, and ``end_pan`` methods of `~.axes.Axes`.

Ticker Locators and Formatters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following deprecated `.Locator`\s and `.Formatter`\s have been removed:

* ``OldScalarFormatter``, ``IndexFormatter`` and ``IndexDateFormatter``; use
`.FuncFormatter` instead.
* ``OldAutoLocator``

The following deprecated properties and methods have been removed:

* ``DateFormatter.illegal_s``
* ``Locator.refresh()`` and the associated helper methods
``NavigationToolbar2.draw()`` and ``ToolViewsPositions.refresh_locators()``
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ The ``on_mappable_changed`` and ``update_bruteforce`` methods of
`~matplotlib.colorbar.Colorbar` are deprecated; both can be replaced by calls
to `~matplotlib.colorbar.Colorbar.update_normal`.

``OldScalarFormatter``, ``IndexFormatter`` and ``DateIndexFormatter``
``OldScalarFormatter``, ``IndexFormatter`` and ``IndexDateFormatter``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These formatters are deprecated. Their functionality can be implemented using
e.g. `.FuncFormatter`.
Expand Down
10 changes: 0 additions & 10 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,16 +1867,6 @@ def _update_offset_text_position(self, bboxes, bboxes2):
"""
raise NotImplementedError('Derived must override')

@_api.deprecated("3.3")
def pan(self, numsteps):
"""Pan by *numsteps* (can be positive or negative)."""
self.major.locator.pan(numsteps)

@_api.deprecated("3.3")
def zoom(self, direction):
"""Zoom in/out on axis; if *direction* is >0 zoom in, else zoom out."""
self.major.locator.zoom(direction)

def axis_date(self, tz=None):
"""
Set up axis ticks and labels to treat data along this Axis as dates.
Expand Down
27 changes: 3 additions & 24 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ def release_pan(self, event):
'motion_notify_event', self.mouse_move)
for ax in self._pan_info.axes:
ax.end_pan()
self._draw()
self.canvas.draw_idle()
self._pan_info = None
self.push_current()

Expand Down Expand Up @@ -3198,7 +3198,7 @@ def release_zoom(self, event):
# "cancel" a zoom action by zooming by less than 5 pixels.
if ((abs(event.x - start_x) < 5 and event.key != "y")
or (abs(event.y - start_y) < 5 and event.key != "x")):
self._draw()
self.canvas.draw_idle()
self._zoom_info = None
return

Expand All @@ -3213,7 +3213,7 @@ def release_zoom(self, event):
(start_x, start_y, event.x, event.y),
self._zoom_info.direction, event.key, twinx, twiny)

self._draw()
self.canvas.draw_idle()
self._zoom_info = None
self.push_current()

Expand All @@ -3228,27 +3228,6 @@ def push_current(self):
for ax in self.canvas.figure.axes}))
self.set_history_buttons()

# Can be removed once Locator.refresh() is removed, and replaced by an
# inline call to self.canvas.draw_idle().
def _draw(self):
for a in self.canvas.figure.get_axes():
xaxis = getattr(a, 'xaxis', None)
yaxis = getattr(a, 'yaxis', None)
locators = []
if xaxis is not None:
locators.append(xaxis.get_major_locator())
locators.append(xaxis.get_minor_locator())
if yaxis is not None:
locators.append(yaxis.get_major_locator())
locators.append(yaxis.get_minor_locator())

for loc in locators:
mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc)
self.canvas.draw_idle()

draw = _api.deprecate_privatize_attribute(
"3.3", alternative="toolbar.canvas.draw_idle()")

def _update_view(self):
"""
Update the viewlim and position from the view and position stack for
Expand Down
31 changes: 3 additions & 28 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import matplotlib as mpl
from matplotlib._pylab_helpers import Gcf
from matplotlib import _api, cbook
from matplotlib import cbook


class Cursors(IntEnum): # Must subclass int for the macOS backend.
Expand Down Expand Up @@ -553,31 +553,6 @@ def update_home_views(self, figure=None):
if a not in self.home_views[figure]:
self.home_views[figure][a] = a._get_view()

# Can be removed once Locator.refresh() is removed, and replaced by an
# inline call to self.figure.canvas.draw_idle().
def _refresh_locators(self):
for a in self.figure.get_axes():
xaxis = getattr(a, 'xaxis', None)
yaxis = getattr(a, 'yaxis', None)
zaxis = getattr(a, 'zaxis', None)
locators = []
if xaxis is not None:
locators.append(xaxis.get_major_locator())
locators.append(xaxis.get_minor_locator())
if yaxis is not None:
locators.append(yaxis.get_major_locator())
locators.append(yaxis.get_minor_locator())
if zaxis is not None:
locators.append(zaxis.get_major_locator())
locators.append(zaxis.get_minor_locator())

for loc in locators:
mpl.ticker._if_refresh_overridden_call_and_emit_deprec(loc)
self.figure.canvas.draw_idle()

refresh_locators = _api.deprecate_privatize_attribute(
"3.3", alternative="self.figure.canvas.draw_idle()")

def home(self):
"""Recall the first view and position from the stack."""
self.views[self.figure].home()
Expand Down Expand Up @@ -732,7 +707,7 @@ def _cancel_action(self):
for zoom_id in self._ids_zoom:
self.figure.canvas.mpl_disconnect(zoom_id)
self.toolmanager.trigger_tool('rubberband', self)
self.toolmanager.get_tool(_views_positions)._refresh_locators()
self.figure.canvas.draw_idle()
self._xypress = None
self._button_pressed = None
self._ids_zoom = []
Expand Down Expand Up @@ -859,7 +834,7 @@ def _cancel_action(self):
self._xypress = []
self.figure.canvas.mpl_disconnect(self._id_drag)
self.toolmanager.messagelock.release(self)
self.toolmanager.get_tool(_views_positions)._refresh_locators()
self.figure.canvas.draw_idle()

def _press(self, event):
if event.button == 1:
Expand Down
37 changes: 1 addition & 36 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,12 @@
date information. This is most useful when used with the `AutoDateLocator`.

* `DateFormatter`: use `~datetime.datetime.strftime` format strings.

* `IndexDateFormatter`: date plots with implicit *x* indexing.
"""

import datetime
import functools
import logging
import math
import re

from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY,
Expand All @@ -189,7 +186,7 @@

__all__ = ('datestr2num', 'date2num', 'num2date', 'num2timedelta', 'drange',
'epoch2num', 'num2epoch', 'set_epoch', 'get_epoch', 'DateFormatter',
'ConciseDateFormatter', 'IndexDateFormatter', 'AutoDateFormatter',
'ConciseDateFormatter', 'AutoDateFormatter',
'DateLocator', 'RRuleLocator', 'AutoDateLocator', 'YearLocator',
'MonthLocator', 'WeekdayLocator',
'DayLocator', 'HourLocator', 'MinuteLocator',
Expand Down Expand Up @@ -607,11 +604,6 @@ class DateFormatter(ticker.Formatter):
`~datetime.datetime.strftime` format string.
"""

@_api.deprecated("3.3")
@property
def illegal_s(self):
return re.compile(r"((^|[^%])(%%)*%s)")

def __init__(self, fmt, tz=None, *, usetex=None):
"""
Parameters
Expand Down Expand Up @@ -639,33 +631,6 @@ def set_tzinfo(self, tz):
self.tz = tz


@_api.deprecated("3.3")
class IndexDateFormatter(ticker.Formatter):
"""Use with `.IndexLocator` to cycle format strings by index."""

def __init__(self, t, fmt, tz=None):
"""
Parameters
----------
t : list of float
A sequence of dates (floating point days).
fmt : str
A `~datetime.datetime.strftime` format string.
"""
if tz is None:
tz = _get_rc_timezone()
self.t = t
self.fmt = fmt
self.tz = tz

def __call__(self, x, pos=0):
"""Return the label for time *x* at position *pos*."""
ind = int(round(x))
if ind >= len(self.t) or ind <= 0:
return ''
return num2date(self.t[ind], self.tz).strftime(self.fmt)


class ConciseDateFormatter(ticker.Formatter):
"""
A `.Formatter` which attempts to figure out the best format to use for the
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from matplotlib.dates import (
date2num, num2date, datestr2num, drange, epoch2num,
num2epoch, DateFormatter, IndexDateFormatter, DateLocator,
num2epoch, DateFormatter, DateLocator,
RRuleLocator, YearLocator, MonthLocator, WeekdayLocator, DayLocator,
HourLocator, MinuteLocator, SecondLocator, rrule, MO, TU, WE, TH, FR,
SA, SU, YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY,
Expand Down
16 changes: 0 additions & 16 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest

import matplotlib as mpl
from matplotlib import _api
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

Expand Down Expand Up @@ -444,21 +443,6 @@ def test_set_params(self):
assert sym.numticks == 8


class TestIndexFormatter:
@pytest.mark.parametrize('x, label', [(-2, ''),
(-1, 'label0'),
(0, 'label0'),
(0.5, 'label1'),
(1, 'label1'),
(1.5, 'label2'),
(2, 'label2'),
(2.5, '')])
def test_formatting(self, x, label):
with _api.suppress_matplotlib_deprecation_warning():
formatter = mticker.IndexFormatter(['label0', 'label1', 'label2'])
assert formatter(x) == label


class TestScalarFormatter:
offset_data = [
(123, 189, 0),
Expand Down
Loading