contourf with data frames

I am trying to make a time height contour plot , here is the script used

dates=mpl.dates.date2num(data.index.to_pydatetime())
xh=list(dates)
dfX=pd.DataFrame(xh)
date2= dfX.groupby(np.arange(len(dfX))//400).mean()
dates=num2date(date2)
dfT=pd.DataFrame(data.iloc[:,5].reshape(400,427).T)
#dfT.insert(loc=0,column='',value=date)
hgtl=data.iloc[0:400:,1]
#plot(dates,dfT.iloc[:,0])
contourf(dates,hgtl,dfT.iloc[0:400:,0].T)

this results in the following error

TypeError Traceback (most recent call last)
<ipython-input-140-d1e220b1ce6a> in <module>()
      8 hgtl=data.iloc[0:400:,1]
      9 #plot(dates,dfT.iloc[:,0])
---> 10 contourf(dates,hgtl,dfT.iloc[0:400:,0].T)

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.pyc in
contourf(*args, **kwargs)
   2781 ax.hold(hold)
   2782 try:
-> 2783 ret = ax.contourf(*args, **kwargs)
   2784 finally:
   2785 ax.hold(washold)

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/__init__.pyc
in inner(ax, *args, **kwargs)
   1810 warnings.warn(msg % (label_namer,
func.__name__),
   1811 RuntimeWarning, stacklevel=2)
-> 1812 return func(ax, *args, **kwargs)
   1813 pre_doc = inner.__doc__
   1814 if pre_doc is None:

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc
in contourf(self, *args, **kwargs)
   5650 self.cla()
   5651 kwargs['filled'] = True
-> 5652 return mcontour.QuadContourSet(self, *args, **kwargs)
   5653 contourf.__doc__ = mcontour.QuadContourSet.contour_doc
   5654

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc in
__init__(self, ax, *args, **kwargs)
   1422 are described in QuadContourSet.contour_doc.
   1423 """
-> 1424 ContourSet.__init__(self, ax, *args, **kwargs)
   1425
   1426 def _process_args(self, *args, **kwargs):

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc in
__init__(self, ax, *args, **kwargs)
    861 self._transform = kwargs.get('transform', None)
    862
--> 863 self._process_args(*args, **kwargs)
    864 self._process_levels()
    865

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc in
_process_args(self, *args, **kwargs)
   1443 self._corner_mask =
mpl.rcParams['contour.corner_mask']
   1444
-> 1445 x, y, z = self._contour_args(args, kwargs)
   1446
   1447 _mask = ma.getmask(z)

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc in
_contour_args(self, args, kwargs)
   1526 args = args[1:]
   1527 elif Nargs <= 4:
-> 1528 x, y, z = self._check_xyz(args[:3], kwargs)
   1529 args = args[3:]
   1530 else:

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc in
_check_xyz(self, args, kwargs)
   1555 y = self.ax.convert_yunits(y)
   1556
-> 1557 x = np.asarray(x, dtype=np.float64)
   1558 y = np.asarray(y, dtype=np.float64)
   1559 z = ma.asarray(args[2], dtype=np.float64)

/home/nuncio/anaconda2/lib/python2.7/site-packages/numpy/core/numeric.pyc in
asarray(a, dtype, order)
    472
    473 """
--> 474 return array(a, dtype, copy=False, order=order)
    475
    476 def asanyarray(a, dtype=None, order=None):

···

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

I undesrstand the problem is with the dates

however

plot(dates,dfT.iloc[:,0])

runs perfectly

Any suggestions to get around it

THanks and regards
nuncio

--
Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html

It looks like you are converting the dates back to datetime objects (`dates
= num2date(date2)`). This smells like a bug in contour that it does not
properly handle units on the input (but `ax.plot` does)

The easiest way around this (with out patching Matplotlib :wink: ) is to plot
with the dates converted to numbers and then manually set the x axis ticker
and locator to be the date related ones.

Tom

···

On Fri, Oct 13, 2017 at 9:00 AM nuncio <nuncio.m at gmail.com> wrote:

I am trying to make a time height contour plot , here is the script used

dates=mpl.dates.date2num(data.index.to_pydatetime())
xh=list(dates)
dfX=pd.DataFrame(xh)
date2= dfX.groupby(np.arange(len(dfX))//400).mean()
dates=num2date(date2)
dfT=pd.DataFrame(data.iloc[:,5].reshape(400,427).T)
#dfT.insert(loc=0,column='',value=date)
hgtl=data.iloc[0:400:,1]
#plot(dates,dfT.iloc[:,0])
contourf(dates,hgtl,dfT.iloc[0:400:,0].T)

this results in the following error

TypeError Traceback (most recent call last)
<ipython-input-140-d1e220b1ce6a> in <module>()
      8 hgtl=data.iloc[0:400:,1]
      9 #plot(dates,dfT.iloc[:,0])
---> 10 contourf(dates,hgtl,dfT.iloc[0:400:,0].T)

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.pyc in
contourf(*args, **kwargs)
   2781 ax.hold(hold)
   2782 try:
-> 2783 ret = ax.contourf(*args, **kwargs)
   2784 finally:
   2785 ax.hold(washold)

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/__init__.pyc
in inner(ax, *args, **kwargs)
   1810 warnings.warn(msg % (label_namer,
func.__name__),
   1811 RuntimeWarning, stacklevel=2)
-> 1812 return func(ax, *args, **kwargs)
   1813 pre_doc = inner.__doc__
   1814 if pre_doc is None:

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc
in contourf(self, *args, **kwargs)
   5650 self.cla()
   5651 kwargs['filled'] = True
-> 5652 return mcontour.QuadContourSet(self, *args, **kwargs)
   5653 contourf.__doc__ = mcontour.QuadContourSet.contour_doc
   5654

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc
in
__init__(self, ax, *args, **kwargs)
   1422 are described in QuadContourSet.contour_doc.
   1423 """
-> 1424 ContourSet.__init__(self, ax, *args, **kwargs)
   1425
   1426 def _process_args(self, *args, **kwargs):

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc
in
__init__(self, ax, *args, **kwargs)
    861 self._transform = kwargs.get('transform', None)
    862
--> 863 self._process_args(*args, **kwargs)
    864 self._process_levels()
    865

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc
in
_process_args(self, *args, **kwargs)
   1443 self._corner_mask =
mpl.rcParams['contour.corner_mask']
   1444
-> 1445 x, y, z = self._contour_args(args, kwargs)
   1446
   1447 _mask = ma.getmask(z)

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc
in
_contour_args(self, args, kwargs)
   1526 args = args[1:]
   1527 elif Nargs <= 4:
-> 1528 x, y, z = self._check_xyz(args[:3], kwargs)
   1529 args = args[3:]
   1530 else:

/home/nuncio/anaconda2/lib/python2.7/site-packages/matplotlib/contour.pyc
in
_check_xyz(self, args, kwargs)
   1555 y = self.ax.convert_yunits(y)
   1556
-> 1557 x = np.asarray(x, dtype=np.float64)
   1558 y = np.asarray(y, dtype=np.float64)
   1559 z = ma.asarray(args[2], dtype=np.float64)

/home/nuncio/anaconda2/lib/python2.7/site-packages/numpy/core/numeric.pyc
in
asarray(a, dtype, order)
    472
    473 """
--> 474 return array(a, dtype, copy=False, order=order)
    475
    476 def asanyarray(a, dtype=None, order=None):
*
TypeError: float() argument must be a string or a number*

I undesrstand the problem is with the dates

however

plot(dates,dfT.iloc[:,0])

runs perfectly

Any suggestions to get around it

THanks and regards
nuncio

--
Sent from:
http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20171013/13b0bfa3/attachment.html>