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

Skip to content

Commit 037b176

Browse files
authored
Merge pull request #10663 from matplotlib/auto-backport-of-pr-10638
Backport PR #10638 on branch v2.2.x
2 parents b67df2d + e5fc2ac commit 037b176

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/matplotlib/dates.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ def date2num(d):
436436
For details see the module docstring.
437437
"""
438438

439+
if hasattr(d, "values"):
440+
# this unpacks pandas series or dataframes...
441+
d = d.values
442+
439443
if ((isinstance(d, np.ndarray) and np.issubdtype(d.dtype, np.datetime64))
440444
or isinstance(d, np.datetime64)):
441445
return _dt64_to_ordinalf(d)

lib/matplotlib/units.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def get_converter(self, x):
156156
if classx is not None:
157157
converter = self.get(classx)
158158

159+
if converter is None and hasattr(x, "values"):
160+
# this unpacks pandas series or dataframes...
161+
x = x.values
162+
159163
# If x is an array, look inside the array for data with units
160164
if isinstance(x, np.ndarray) and x.size:
161165
xravel = x.ravel()

0 commit comments

Comments
 (0)