Skip to content
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

datetime handling for spikes #3736

Merged
merged 2 commits into from
May 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions holoviews/plotting/mpl/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ...core.options import Store, abbreviated_exception
from ...core.util import (
OrderedDict, match_spec, unique_iterator, basestring, max_range,
isfinite, datetime_types, dt_to_int, dt64_to_dt, search_indices,
isfinite, dt_to_int, dt64_to_dt, search_indices,
unique_array, isscalar, isdatetime
)
from ...element import Raster, HeatMap
Expand Down Expand Up @@ -996,7 +996,7 @@ def _get_dims(self, element):

def _create_bars(self, axis, element):
# Get style and dimension information
values = self.values
values = self.values
if self.group_index != 0:
self.warning('Bars group_index plot option is deprecated '
'and will be ignored, set stacked=True/False '
Expand Down Expand Up @@ -1173,10 +1173,13 @@ def get_data(self, element, ranges, style):

pos = self.position
if ndims > 1:
data = [[(x, pos), (x, pos+y)] for x, y in element.array([0, 1])]
data = element.columns([0, 1])
xs, ys = data[dimensions[0]], data[dimensions[1]]
data = [[(x, pos), (x, pos+y)] for x, y in zip(xs, ys)]
else:
xs = element.array([0])
height = self.spike_length
data = [[(x[0], pos), (x[0], pos+height)] for x in element.array([0])]
data = [[(x[0], pos), (x[0], pos+height)] for x in xs]

if self.invert_axes:
data = [(line[0][::-1], line[1][::-1]) for line in data]
Expand All @@ -1188,10 +1191,13 @@ def get_data(self, element, ranges, style):
cols = []
for i, vs in enumerate((xs, ys)):
vs = np.array(vs)
if (vs.dtype.kind == 'M' or (len(vs) and isinstance(vs[0], datetime_types))) and i < len(dims):
dt_format = Dimension.type_formatters[np.datetime64]
if isdatetime(vs):
dt_format = Dimension.type_formatters.get(
type(vs[0]),
Dimension.type_formatters[np.datetime64]
)
vs = date2num(vs)
dims[i] = dims[i](value_format=DateFormatter(dt_format))
vs = np.array([dt_to_int(v, 'D') for v in vs])
cols.append(vs)
clean_spikes.append(np.column_stack(cols))

Expand Down Expand Up @@ -1256,4 +1262,3 @@ class SideSpikesPlot(AdjoinedPlot, SpikesPlot):
Whether and where to display the yaxis, bare options allow suppressing
all axis labels including ticks and ylabel. Valid options are 'left',
'right', 'bare' 'left-bare' and 'right-bare'.""")