Skip to content

[BUG] KDE plot and color kwarg #3187

@TomAugspurger

Description

@TomAugspurger

Not sure if this is a bug here or not.

import pandas as pd
import numpy as np

d = {'noise': np.random.randn(100).cumsum(),
     'trend': np.arange(100)}

df = pd.DataFrame(d)
df['resid'] = pd.ols(y=df.noise, x=df.trend).resid
df['resid'].plot(kind='kde', color='k')

Will give this traceback:

In [14]: Traceback (most recent call last):
      File "/usr/local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/figure.py", line 927, in draw
        func(*args)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/axes.py", line 1999, in draw
        a.draw(renderer)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
        draw(artist, renderer, *args, **kwargs)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/lines.py", line 494, in draw
        gc.set_foreground(self._color)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 189, in set_foreground
        GraphicsContextBase.set_foreground(self, fg, isRGB)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 878, in set_foreground
        self._rgb = colors.colorConverter.to_rgba(fg)
      File "/usr/local/lib/python2.7/site-packages/matplotlib/colors.py", line 354, in to_rgba
        raise ValueError('to_rgba: Invalid rgba arg "%s"\n%s' % (str(arg), exc))
    ValueError: to_rgba: Invalid rgba arg "['k']"
    need more than 1 value to unpack

    If you suspect this is an IPython bug, please report it at:
        https://github.com/ipython/ipython/issues
    or send an email to the mailing list at [email protected]

    You can print a more detailed traceback right now with "%tb", or use "%debug"
    to interactively debug it.

    Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
        %config Application.verbose_crash=True

I haven't add a chance to look through the plotting code yet to see if this should work or not, but it seems like it should.

In [14]: pd.__version__
Out[14]: '0.11.0.dev-7d11531'

And this happens in IPython both with and without pylab mode. I've tried with other rgba values and they seem to fail too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions