Skip to content

Deprecate plot_date() #18154

Closed
Closed
@timhoffm

Description

@timhoffm

This is a writeup / proposal to serve as a basis for discussion in the dev call on 03 Aug 2020.

plot_date() is essentially a thin wrapper around plot() but has different defaults for fmt. This causes confusion #17548, #18141.

Context

  • Use case: plot_date() dates back way before Matplotlib supported units. It's nowadays only necessary if you have plain numbers (in matplotlibs epoch). datetimes are directly handled in plot() via the unit system.
    While there may be users for plot_date(), i suppose it's rather a niche application.

  • Naming: The name is a bit misleading in that it suggests that you should use the function if you want to plot dates. This implicitly includes datetime / date which would be misleading. I'm suspecting that it may lead users with datetime/date objects on the wrong track. (plot_as_date() would have been more appropriate, but we're not gonna change that).

  • API design: plot_date() is an ad-hoc aggregation of plot() and axis_date()

      def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False, **kwargs):
          if xdate:
              self.xaxis_date(tz)
          if ydate:
              self.yaxis_date(tz)
          return self.plot(x, y, fmt, **kwargs)
    

Recommendation

Given the above context, I propose to deprecate plot_date() in favor of ax.plot() and ax.x/yaxis.axis_date().

At the same time, deprecate ax.x/yaxis_date() in favor of ax.x/yaxis.axis_date(). This reduces the API footprint of Axes. IMHO we don't need to have wrappers x/yfoo() wrappers for every foo() function on the axis. While common ones like set_x/ylabel() have a justification, it's fine in general to use ax.xaxis.foo().

Alternatives:

  • Keep as is - I wouldn't do that as it's confusing users.
  • Change the default fmt to match plot() - Such a default change requires as much user action as the deprecation, but we keep all the unnecessary redundancy / imperfect naming.
  • Only soft-deprecate (i.e. add a note to discourage the use but keep the function). This would be an option if we're strongly concerned with not forcing users to change their plot_date() code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions