Cannot plot fully masked array against datetimes · Issue #11337 · matplotlib/matplotlib · GitHub
Skip to content

Cannot plot fully masked array against datetimes #11337

Description

@logdog

Bug report

Bug summary
Cannot plot a fully masked array agaisnt an array of datetimes. A ValueError is raised for a seemingly unrelated reason. Surprisingly, matplotlib has no problem plotting a fully masked array by itself.

Code for reproduction

import matplotlib.pyplot as plt
from datetime import datetime
import numpy as np

x = np.array([
    datetime(2017, 1, 1), 
    datetime(2017, 1, 2), 
    datetime(2017, 1, 3),
    datetime(2017, 1, 4),
    datetime(2017, 1, 5)
])

y = np.array([1,2,3,4,5])
m = np.ma.masked_greater(y, 0)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, m)
plt.show()

Actual outcome

[super big traceback, only showing the most recent to save space...]
/usr/lib64/python3.5/dist-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
    258 
    259     ix = int(x)
--> 260     dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
    261 
    262     remainder = float(x) - ix
ValueError: ordinal must be >= 1

Expected outcome
An empty graph. If you comment out x and don't plot against it, then matplotlib has no problem displaying an empty graph. It is only when you plot against a datetime array this is an issue.

Matplotlib version

  • Operating system: GNU/Linux
  • Matplotlib version: 2.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.5.5
  • Jupyter version (if applicable): 4.3.0
  • Other libraries: numpy, datetime

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions