Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 scatter plot error - possibly data type - TypeError: nan is not a string
#1
Hi,

Can anyone help me with this error?
I suspect it is something to do with the data type, but don't know how to resolve.
I'm trying to plot a 2 user system dates against each other and am getting the error below.

print(type(DialogUsers.TRDAT)) 
<class 'pandas.core.series.Series'> 

plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) 
plt.show() 
---------------------------------------------------------------------------
Error:
TypeError Traceback (most recent call last) <ipython-input-7-3277b90008cc> in <module>() ----> 1 plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) 2 plt.show() ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs) 3473 vmin=vmin, vmax=vmax, alpha=alpha, 3474 linewidths=linewidths, verts=verts, -> 3475 edgecolors=edgecolors, data=data, **kwargs) 3476 finally: 3477 ax._hold = washold ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs) 1865 "the Matplotlib list!)" % (label_namer, func.__name__), 1866 RuntimeWarning, stacklevel=2) -> 1867 return func(ax, *args, **kwargs) 1868 1869 inner.__doc__ = _add_data_doc(inner.__doc__, ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs) 4245 edgecolors = 'face' 4246 -> 4247 self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) 4248 x = self.convert_xunits(x) 4249 y = self.convert_yunits(y) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _process_unit_info(self, xdata, ydata, kwargs) 2170 # we only need to update if there is nothing set yet. 2171 if not self.yaxis.have_units(): -> 2172 self.yaxis.update_units(ydata) 2173 2174 # process kwargs 2nd since these will override default units ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axis.py in update_units(self, data) 1467 neednew = self.converter != converter 1468 self.converter = converter -> 1469 default = self.converter.default_units(data, self) 1470 if default is not None and self.units is None: 1471 self.set_units(default) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in default_units(data, axis) 113 # default_units->axis_info->convert 114 if axis.units is None: --> 115 axis.set_units(UnitData(data)) 116 else: 117 axis.units.update(data) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in __init__(self, data) 180 self._counter = itertools.count(start=0) 181 if data is not None: --> 182 self.update(data) 183 184 def update(self, data): ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in update(self, data) 199 for val in OrderedDict.fromkeys(data): 200 if not isinstance(val, VALID_TYPES): --> 201 raise TypeError("{val!r} is not a string".format(val=val)) 202 if val not in self._mapping: 203 self._mapping[val] = next(self._counter) TypeError: nan is not a string
Thanks,
Ciarán
Yoriz wrote Mar-24-2019, 11:21 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Quote
#2
plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT)
plt.show()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-3277b90008cc> in <module>()
----> 1 plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT)
      2 plt.show()

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
   3473                          vmin=vmin, vmax=vmax, alpha=alpha,
   3474                          linewidths=linewidths, verts=verts,
-> 3475                          edgecolors=edgecolors, data=data, **kwargs)
   3476     finally:
   3477         ax._hold = washold

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
   1865                         "the Matplotlib list!)" % (label_namer, func.__name__),
   1866                         RuntimeWarning, stacklevel=2)
-> 1867             return func(ax, *args, **kwargs)
   1868 
   1869         inner.__doc__ = _add_data_doc(inner.__doc__,

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   4245             edgecolors = 'face'
   4246 
-> 4247         self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
   4248         x = self.convert_xunits(x)
   4249         y = self.convert_yunits(y)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _process_unit_info(self, xdata, ydata, kwargs)
   2170             # we only need to update if there is nothing set yet.
   2171             if not self.yaxis.have_units():
-> 2172                 self.yaxis.update_units(ydata)
   2173 
   2174         # process kwargs 2nd since these will override default units

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axis.py in update_units(self, data)
   1467         neednew = self.converter != converter
   1468         self.converter = converter
-> 1469         default = self.converter.default_units(data, self)
   1470         if default is not None and self.units is None:
   1471             self.set_units(default)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in default_units(data, axis)
    113         # default_units->axis_info->convert
    114         if axis.units is None:
--> 115             axis.set_units(UnitData(data))
    116         else:
    117             axis.units.update(data)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in __init__(self, data)
    180         self._counter = itertools.count(start=0)
    181         if data is not None:
--> 182             self.update(data)
    183 
    184     def update(self, data):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in update(self, data)
    199         for val in OrderedDict.fromkeys(data):
    200             if not isinstance(val, VALID_TYPES):
--> 201                 raise TypeError("{val!r} is not a string".format(val=val))
    202             if val not in self._mapping:
    203                 self._mapping[val] = next(self._counter)

TypeError: nan is not a string


Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Scaled scatter modification yvrob 1 92 Nov-08-2019, 04:05 AM
Last Post: yvrob
  plot multiple employee sales data in a single graph pitanshu 0 94 Oct-24-2019, 01:56 PM
Last Post: pitanshu
  TypeError: unsupported operand type(s) for -: 'str' and 'str' Balaji 4 264 Oct-11-2019, 10:29 AM
Last Post: buran
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 228 Sep-18-2019, 08:32 AM
Last Post: buran
  Type Error: bad operand type for unary +: 'str' Psypher1 2 860 Aug-12-2019, 02:30 PM
Last Post: Psypher1
  catch input type error mcmxl22 5 253 Aug-11-2019, 07:33 AM
Last Post: wavic
  TypeError: int() argument must be a string or a number, not 'NoneType' Hadad 2 589 Jul-30-2019, 07:22 PM
Last Post: Hadad
  How to plot multiple scatter plots in seaborn vikola 2 944 Jul-14-2019, 10:30 AM
Last Post: vikola
  Type error: dump() missing 1 required positional argument: fp jaycuff13 2 1,287 Jul-13-2019, 10:21 AM
Last Post: jaycuff13
  TypeError: can't multiply sequence by non-int of type 'str' rregorr 2 323 Jun-28-2019, 04:43 PM
Last Post: Yoriz

Forum Jump:


Users browsing this thread: 1 Guest(s)