Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
_determine_cmap_params supports datetime64
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Dec 19, 2018
1 parent c2923b2 commit 0a01e7c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,23 @@ def _determine_cmap_params(plot_data, vmin=None, vmax=None, cmap=None,
"""
import matplotlib as mpl

calc_data = np.ravel(plot_data[np.isfinite(plot_data)])
if np.issubdtype(plot_data.dtype, np.datetime64):
calc_data = np.ravel(plot_data[~np.isnat(plot_data)])
possibly_divergent = False
elif np.issubdtype(plot_data.dtype, np.timedelta64):
calc_data = np.ravel(plot_data[~np.isnat(plot_data)]).astype('float64')
# Setting center=False prevents a divergent cmap
possibly_divergent = center is not False
else:
calc_data = np.ravel(plot_data[np.isfinite(plot_data)])
# Setting center=False prevents a divergent cmap
possibly_divergent = center is not False

# Handle all-NaN input data gracefully
if calc_data.size == 0:
# Arbitrary default for when all values are NaN
calc_data = np.array(0.0)

# Setting center=False prevents a divergent cmap
possibly_divergent = center is not False

# Set center to 0 so math below makes sense but remember its state
center_is_none = False
if center is None:
Expand Down

0 comments on commit 0a01e7c

Please sign in to comment.