-1

I need to create a three dimensional line chart in which x-axis is dates y-axis is sales and z-axis is ids. I have used the following code:

# Data for a three-dimensional line
zline = df_csv['loc id']
xline = df_csv['date']
yline = df_csv['total_sales']
ax.plot3D(xline, yline, zline, 'gray')

This is the error that it generates:

 ValueErrorTraceback (most recent call last)
    <ipython-input-10-f2edc42bd85e> in <module>()
      4 xline = df_csv['date']
      5 yline = df_csv['total_sales']
----> 6 ax.plot3D(xline, yline, zline, 'gray')
      7 
      8 # Data for three-dimensional scattered points

C:\Users\fatima.arshad\AppData\Local\Continuum\anaconda2\lib\site-packages\mpl_toolkits\mplot3d\axes3d.pyc in plot(self, xs, ys, *args, **kwargs)
   1570 
   1571         xs, ys, zs = art3d.juggle_axes(xs, ys, zs, zdir)
-> 1572         self.auto_scale_xyz(xs, ys, zs, had_data)
   1573         return lines
   1574 

C:\Users\fatima.arshad\AppData\Local\Continuum\anaconda2\lib\site-packages\mpl_toolkits\mplot3d\axes3d.pyc in auto_scale_xyz(self, X, Y, Z, had_data)
    500         # to what the minimum sized rectangular volume holds the
    501         # data.
--> 502         self.xy_dataLim.update_from_data_xy(np.array([x, y]).T, not had_data)
    503         if z is not None:
    504             self.zz_dataLim.update_from_data_xy(np.array([z, z]).T, not had_data)

C:\Users\fatima.arshad\AppData\Local\Continuum\anaconda2\lib\site-packages\matplotlib\transforms.pyc in update_from_data_xy(self, xy, ignore, updatex, updatey)
    925             return
    926 
--> 927         path = Path(xy)
    928         self.update_from_path(path, ignore=ignore,
    929                                     updatex=updatex, updatey=updatey)

C:\Users\fatima.arshad\AppData\Local\Continuum\anaconda2\lib\site-packages\matplotlib\path.pyc in __init__(self, vertices, codes, _interpolation_steps, closed, readonly)
    130             and codes as read-only arrays.
    131         """
--> 132         vertices = _to_unmasked_float_array(vertices)
    133         if (vertices.ndim != 2) or (vertices.shape[1] != 2):
    134             raise ValueError(

C:\Users\fatima.arshad\AppData\Local\Continuum\anaconda2\lib\site-packages\matplotlib\cbook\__init__.pyc in _to_unmasked_float_array(x)
   2050         return np.ma.asarray(x, float).filled(np.nan)
   2051     else:
-> 2052         return np.asarray(x, float)
   2053 
   2054 

C:\Users\fatima.arshad\AppData\Local\Continuum\anaconda2\lib\site-packages\numpy\core\numeric.pyc in asarray(a, dtype, order)
    536 
    537     """
--> 538     return array(a, dtype, copy=False, order=order)
    539 
    540 

ValueError: invalid literal for float(): 1/1/2016

How do I incorporate dates? It should display the point to exact date and not round it to years.

Newbie
  • 151
  • 1
  • 1
  • 11

1 Answers1

0

datetime has to be converted to python datetime first. Here is the solution for anyone else;

xline = matplotlib.dates.date2num(pd.to_datetime(df_csv['date']))
Newbie
  • 151
  • 1
  • 1
  • 11