Closed
Description
import numpy as np, matplotlib.pyplot as plt
x = [3, 5] + [np.nan] * 10000 + [0, 2]
plt.plot(x, x)
plt.xlim([0, 2])
plt.show()
As of matplotlib 1.5.0, this fails to plot the section of the line between 0 and 2 (which can be seen by replacing 10000 by e.g. 1).
This is due to incorrect caching logic in Line2D.recache
and more specifically in Line2D._is_sorted
, which believes that the line's x-points are sorted because nanmin(diff(x)) > 0
(but this skips across the zero).
Related to #5365.
I believe a proper fix for both issues would be to replace the implementation of _is_sorted
by something like x = x[~np.isnan(x)]; return len(x) == 0 or np.diff(x).min() >= 0
.