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

ValueError: Invalid RGBA argument: nan #9688

Closed
Solarmew opened this issue Nov 4, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@Solarmew
Copy link

commented Nov 4, 2017

I'm working through an example in a Machine Learning course on Coursera. They're doing all their examples in the Jupyter notebook, but I'm using PyCharm and I've ran into this issue trying to make a scatter plot.

Here's my code:

import pandas as pd
from sklearn.model_selection import train_test_split
from matplotlib import cm

fruits = pd.read_table("fruit_data_with_colors.txt")

look_up_fruit_name = dict(zip(fruits.fruit_label.unique(), fruits.fruit_name.unique()))
print(fruits.head())

x = fruits[['mass', 'width', 'height']]
y = fruits['fruit_label']

x_train, y_train, x_test, y_test = train_test_split(x, y, random_state = 0)

cmap = cm.get_cmap('gnuplot')
scatter = pd.scatter_matrix(x_train, c=y_train, marker='o', s=40, hist_kwds={'bins':15}, figsize=(12,12), cmap=cmap)

and here's the output:

fruit_label fruit_name fruit_subtype  mass  width  height  color_score
0            1      apple  granny_smith   192    8.4     7.3         0.55
1            1      apple  granny_smith   180    8.0     6.8         0.59
2            1      apple  granny_smith   176    7.4     7.2         0.60
3            2   mandarin      mandarin    86    6.2     4.7         0.80
4            2   mandarin      mandarin    84    6.0     4.6         0.79
Traceback (most recent call last):
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\colors.py", line 141, in to_rgba
    rgba = _colors_full_map.cache[c, alpha]
KeyError: (nan, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/solar/Desktop/Projects/ML/MachineLearning/test.py", line 21, in <module>
    scatter = pd.plotting.scatter_matrix(x_train, c=col, marker='o', s=40, hist_kwds={'bins':15}, figsize=(12,12), cmap=cmap)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\plotting\_misc.py", line 106, in scatter_matrix
    marker=marker, alpha=alpha, **kwds)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\__init__.py", line 1898, in inner
    return func(ax, *args, **kwargs)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\axes\_axes.py", line 4034, in scatter
    alpha=alpha
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\collections.py", line 902, in __init__
    Collection.__init__(self, **kwargs)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\collections.py", line 140, in __init__
    self.set_facecolor(facecolors)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\collections.py", line 681, in set_facecolor
    self._set_facecolor(c)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\collections.py", line 666, in _set_facecolor
    self._facecolors = mcolors.to_rgba_array(c, self._alpha)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\colors.py", line 239, in to_rgba_array
    result[i] = to_rgba(cc, alpha)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\colors.py", line 143, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\colors.py", line 194, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: nan

Process finished with exit code 1

should look like this:
https://ibb.co/i7mqxb

  • Operating system: win 10
  • Matplotlib version: 2.0.2
  • Matplotlib backend: TkAgg
  • Python version: 3.6.2
@jklymak

This comment has been minimized.

Copy link
Contributor

commented Nov 4, 2017

Pretty sure this is fixed 2.1 #8658 In the future, its easier on the developers if you make a self-contained example that has as few dependencies as possible.

Feel free to re-open if 2.1 doesn't help you

@jklymak jklymak closed this Nov 4, 2017

@Solarmew

This comment has been minimized.

Copy link
Author

commented Nov 4, 2017

@jklymak thanks, I saw that thread when I was looking for a solution, but I didn't understand it :(

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Nov 4, 2017

Upgrade from 2.0.2 to 2.1, though 2.1 has a few rough edges as well...

@Solarmew

This comment has been minimized.

Copy link
Author

commented Nov 5, 2017

yikes ... so i tried that and it seemed to be doing ok, but then everything exploded %\ ...

C:\Users\solar>python -mpip install -U matplotlib
Collecting matplotlib
  Downloading matplotlib-2.1.0-cp36-cp36m-win32.whl (8.5MB)
    100% |████████████████████████████████| 8.5MB 142kB/s
Requirement already up-to-date: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\solar\appdata\local\programs\python\python36-32\lib\site-packages (from matplotlib)
Collecting six>=1.10 (from matplotlib)
  Downloading six-1.11.0-py2.py3-none-any.whl
Collecting pytz (from matplotlib)
  Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
    100% |████████████████████████████████| 512kB 1.9MB/s
Requirement already up-to-date: cycler>=0.10 in c:\users\solar\appdata\local\programs\python\python36-32\lib\site-packages (from matplotlib)
Requirement already up-to-date: python-dateutil>=2.0 in c:\users\solar\appdata\local\programs\python\python36-32\lib\site-packages (from matplotlib)
Collecting numpy>=1.7.1 (from matplotlib)
  Downloading numpy-1.13.3-2-cp36-none-win32.whl (6.8MB)
    100% |████████████████████████████████| 6.8MB 170kB/s
Installing collected packages: six, pytz, numpy, matplotlib
  Found existing installation: six 1.10.0
    Uninstalling six-1.10.0:
      Successfully uninstalled six-1.10.0
  Found existing installation: pytz 2017.2
    Uninstalling pytz-2017.2:
      Successfully uninstalled pytz-2017.2
  Found existing installation: numpy 1.13.1+mkl
    Uninstalling numpy-1.13.1+mkl:
      Successfully uninstalled numpy-1.13.1+mkl
Exception:
Traceback (most recent call last):
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 387, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\solar\\AppData\\Local\\Temp\\pip-41sv0npw-uninstall\\users\\solar\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\numpy\\core\\mkl_rt.dll'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 795, in install
    requirement.commit_uninstall()
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_install.py", line 767, in commit_uninstall
    self.uninstalled.commit()
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_uninstall.py", line 142, in commit
    rmtree(self.save_dir)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\retrying.py", line 212, in call
    raise attempt.get()
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\six.py", line 686, in reraise
    raise value
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\utils\__init__.py", line 102, in rmtree
    onerror=rmtree_errorhandler)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 494, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 384, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  [Previous line repeated 7 more times]
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 389, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\solar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\utils\__init__.py", line 114, in rmtree_errorhandler
    func(path)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\solar\\AppData\\Local\\Temp\\pip-41sv0npw-uninstall\\users\\solar\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\numpy\\core\\mkl_rt.dll'
@jklymak

This comment has been minimized.

Copy link
Contributor

commented Nov 5, 2017

Unless you have some strong reason not to, I strongly suggest you use Anaconda.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.