-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
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 inplot()via the unit system.
While there may be users forplot_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/datewhich would be misleading. I'm suspecting that it may lead users withdatetime/dateobjects 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 ofplot()andaxis_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
fmtto matchplot()- 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.