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

DataFrame.plot error when both 'color' and 'style' arguments are passed #9671

Closed
davidbrochart opened this issue Mar 17, 2015 · 6 comments
Closed
Labels
Milestone

Comments

@davidbrochart
Copy link

In pandas 0.15.2, when passing both arguments 'color' and 'style' to the plot method, there is an error which I think should be raised only when there is a color symbol in the style string. But in the example below, the error is raised even though there is no color symbol in the line string:

from pandas import DataFrame
import numpy as np
df = DataFrame({'a': np.random.rand(10), 'b': np.random.rand(10), 'c': np.random.rand(10)})
df.plot(color = ['red', 'black', 'blue'], style = ['-', '--', '-'])

The error is not clear (TypeError: expected string or buffer). This should be fixed, although it is easy to work around:

df.plot(style = ['r-', 'k--', 'b-'])
@TomAugspurger
Copy link
Contributor

It looks like your example is supposed to work, it's just that our regex in this block checking for the color is expecting a string, not a list of strings. Notice that df.a.plot(color = 'red', style = '-') works correcly.

It should be a pretty quick fix, just check if style is an array-like of strings and check if any of those match the regex. Interested in submitting a PR?

@TomAugspurger TomAugspurger added the Visualization plotting label Mar 17, 2015
@TomAugspurger TomAugspurger added this to the 0.16.1 milestone Mar 17, 2015
@davidbrochart
Copy link
Author

Sure, submitting a PR will be a first time for me, but there is always a first time ;-)

@TomAugspurger
Copy link
Contributor

There is indeed! We're here if you have troubles. The only trick is to correctly determine whether it's a string or list. There's a function in pandas/core/common.py is_list_like. You should be able to use it with com.is_list_like.

davidbrochart pushed a commit to davidbrochart/pandas that referenced this issue Mar 17, 2015
@davidbrochart
Copy link
Author

It looks like I've submitted a PR ;-)
#9673

@davidbrochart
Copy link
Author

I've submitted a new PR #9674 with a test for the bug fix.

davidbrochart pushed a commit to davidbrochart/pandas that referenced this issue Apr 6, 2015
…en both 'color' and 'style' keywords were passed and there was no color symbol in the style strings (this should be allowed)
davidbrochart added a commit to davidbrochart/pandas that referenced this issue Apr 6, 2015
TomAugspurger pushed a commit that referenced this issue Apr 6, 2015
…olor' and 'style' keywords were passed and there was no color symbol in the style strings (this should be allowed)
@TomAugspurger
Copy link
Contributor

Closed via #9674

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants