Thanks to visit codestin.com
Credit goes to github.com

Skip to content

span_where fails with timeseries on the x-axis #15973

Closed
@szeitlin

Description

@szeitlin

Bug report

Bug summary

Similar to #3872

Code for reproduction

I can't attach a CSV or an .ipynb, but I'll zip them up together and attach that.
span_where.zip

collection = collections.BrokenBarHCollection.span_where(df.index,ymin=0,ymax=df['numeric_col'].max(),
                                                         where=df['bool_col']==True,
                                                            facecolor='g', 
                                                            edgecolor='red', 
                                                            linewidth=2.0, linestyle='--', 
                                                            alpha=0.2, 
                                                            label='span')
axes.add_collection(collection)

Actual outcome

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-264dcc0313f6> in <module>
      6                                                             linewidth=2.0, linestyle='--',
      7                                                             alpha=0.2,
----> 8                                                             label='span')
      9 axes.add_collection(collection)

/opt/anaconda3/envs/eda/lib/python3.7/site-packages/matplotlib/collections.py in span_where(x, ymin, ymax, where, **kwargs)
   1131 
   1132         collection = BrokenBarHCollection(
-> 1133             xranges, [ymin, ymax - ymin], **kwargs)
   1134         return collection
   1135 

/opt/anaconda3/envs/eda/lib/python3.7/site-packages/matplotlib/collections.py in __init__(self, xranges, yrange, **kwargs)
   1111                   (xmin + xwidth, ymin),
   1112                   (xmin, ymin)] for xmin, xwidth in xranges]
-> 1113         PolyCollection.__init__(self, verts, **kwargs)
   1114 
   1115     @staticmethod

/opt/anaconda3/envs/eda/lib/python3.7/site-packages/matplotlib/collections.py in __init__(self, verts, sizes, closed, **kwargs)
   1044         Collection.__init__(self, **kwargs)
   1045         self.set_sizes(sizes)
-> 1046         self.set_verts(verts, closed)
   1047         self.stale = True
   1048 

/opt/anaconda3/envs/eda/lib/python3.7/site-packages/matplotlib/collections.py in set_verts(self, verts, closed)
   1065                     codes[0] = mpath.Path.MOVETO
   1066                     codes[-1] = mpath.Path.CLOSEPOLY
-> 1067                     self._paths.append(mpath.Path(xy, codes))
   1068                 else:
   1069                     self._paths.append(mpath.Path(xy))

/opt/anaconda3/envs/eda/lib/python3.7/site-packages/matplotlib/path.py in __init__(self, vertices, codes, _interpolation_steps, closed, readonly)
    125             and codes as read-only arrays.
    126         """
--> 127         vertices = _to_unmasked_float_array(vertices)
    128         if vertices.ndim != 2 or vertices.shape[1] != 2:
    129             raise ValueError(

/opt/anaconda3/envs/eda/lib/python3.7/site-packages/matplotlib/cbook/__init__.py in _to_unmasked_float_array(x)
   1388         return np.ma.asarray(x, float).filled(np.nan)
   1389     else:
-> 1390         return np.asarray(x, float)
   1391 
   1392 

/opt/anaconda3/envs/eda/lib/python3.7/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
     83 
     84     """
---> 85     return array(a, dtype, copy=False, order=order)
     86 
     87 

TypeError: float() argument must be a string or a number, not 'Timestamp'

Expected outcome

this works:

axes = df['numeric_col'].plot() 
axes.fill_between(df.index,0,df['numeric_col'].max(),where=df['bool_col']==False, interpolate=True, color='lightskyblue')

Screen Shot 2019-12-17 at 5 39 52 PM

Matplotlib version

  • Operating system: Mac OS 10.14.6

  • Matplotlib version: 3.1.1

  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline

  • Python version: python 3.7.5

  • Jupyter version (if applicable):
    jupyter 1.0.0 py37_7
    jupyter_client 5.3.4 py37_0
    jupyter_console 6.0.0 py37_0
    jupyter_core 4.6.1 py37_0

  • Other libraries:
    pandas 0.25.3

installed with conda

conda default channel

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions