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

hl_span with DatetimeIndex having issues #9

Open
cancan101 opened this issue Apr 21, 2014 · 0 comments
Open

hl_span with DatetimeIndex having issues #9

cancan101 opened this issue Apr 21, 2014 · 0 comments

Comments

@cancan101
Copy link

This is the error:

----> 6 fig.hl_span("2014-4-14", "2014-4-14", color='red')

/usr/lib/python2.7/site-packages/ts_charting/span.pyc in hl_span_figure(self, *args, **kwargs)
     36     grapher = self.grapher
     37     kwargs['grapher'] = grapher
---> 38     return highlight_span(*args, **kwargs)
     39 
     40 charting.Figure.hl_span = hl_span_figure

/usr/lib/python2.7/site-packages/ts_charting/span.pyc in highlight_span(start, end, color, alpha, grapher)
     31         end = index.get_loc(end)
     32 
---> 33     grapher.ax.axvspan(start, end, color=color, alpha=alpha)
     34 
     35 def hl_span_figure(self, *args, **kwargs):

/usr/lib64/python2.7/site-packages/matplotlib/axes.pyc in axvspan(self, xmin, xmax, ymin, ymax, **kwargs)
   3647 
   3648         verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
-> 3649         p = mpatches.Polygon(verts, **kwargs)
   3650         p.set_transform(trans)
   3651         self.add_patch(p)

/usr/lib64/python2.7/site-packages/matplotlib/patches.pyc in __init__(self, xy, closed, **kwargs)
    806         Patch.__init__(self, **kwargs)
    807         self._closed = closed
--> 808         self.set_xy(xy)
    809 
    810     def get_path(self):

/usr/lib64/python2.7/site-packages/matplotlib/patches.pyc in set_xy(self, xy)
    831             if len(xy) > 2 and (xy[0] == xy[-1]).all():
    832                 xy = xy[:-1]
--> 833         self._path = Path(xy, closed=self._closed)
    834 
    835     _get_xy = get_xy

/usr/lib64/python2.7/site-packages/matplotlib/path.pyc in __init__(self, vertices, codes, _interpolation_steps, closed, readonly)
    131             vertices = vertices.astype(np.float_).filled(np.nan)
    132         else:
--> 133             vertices = np.asarray(vertices, np.float_)
    134 
    135         if codes is not None:

/usr/lib64/python2.7/site-packages/numpy/core/numeric.pyc in asarray(a, dtype, order)
    458 
    459     """
--> 460     return array(a, dtype, copy=False, order=order)
    461 
    462 def asanyarray(a, dtype=None, order=None):

TypeError: float() argument must be a string or a number

I beleive this is caused by the assumption here:
https://github.com/dalejung/ts-charting/blob/master/ts_charting/span.py#L28 that get_loc returns an int.

Rather it returns a slice:

In [455]:
fig.grapher.index.get_loc("2014-4-14")

Out[455]:
slice(0, 421, None)

In [456]:
fig.grapher.index

Out[456]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-04-14 09:30:00, ..., 2014-04-21 11:54:55]
Length: 1840, Freq: None, Timezone: None

I would guess that if the return value of get_loc is a slice, then the start of the slice should be used for the start index and the stop should be used for the end:

start = index.get_loc(start).start
end= index.get_loc(end).stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant