Skip to content

Surprising datetime autoscaling after passing empty data #17586

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

Closed
mwaskom opened this issue Jun 7, 2020 · 0 comments · Fixed by #17781
Closed

Surprising datetime autoscaling after passing empty data #17586

mwaskom opened this issue Jun 7, 2020 · 0 comments · Fixed by #17781

Comments

@mwaskom
Copy link

mwaskom commented Jun 7, 2020

Bug report

Bug summary

The automatic limits for datetime axes depend in surprising ways on the presence of artists without any data.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

Case 1:

If a datetime plot follows an empty plot, the autoscaling on the date axis are not what one would expect:

f, ax = plt.subplots()
x = np.arange("2010-01-01", "2011-01-01", dtype="datetime64[D]")
ax.scatter([], [])
ax.scatter(x, np.arange(len(x)))

image

While I can't account for the specific choice of limits, I gather that the first plot sets the units on the axes in a way that interferes with the subsequent plot. And indeed, we can fix the problem by setting a dtype on our null data.

Case 2:

f, ax = plt.subplots()
x = np.arange("2010-01-01", "2011-01-01", dtype="datetime64[D]")
null = np.array([], x.dtype)
ax.scatter(null, [])
ax.scatter(x, np.arange(len(x)))

image

But this does not work for all functions. Consider the case of fill_between.

Case 3:

f, ax = plt.subplots()
x = np.arange("2010-01-01", "2011-01-01", dtype="datetime64[D]")
null = np.array([], x.dtype)
ax.fill_between(null, [])
ax.fill_between(x, np.arange(len(x)))

image

In summary, I think Case 1 is not a bug (it would be nice to defer unit setting for empty data, but I can easily imagine that this is hard/impossible). But I can't account for Case 3.

Matplotlib version

  • Operating system: macos
  • Matplotlib version: 3.2.1
  • Matplotlib backend (print(matplotlib.get_backend())): pylab inline
  • Python version: 3.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants