0

I've checked a few threads already, like: itertools.cycle().next()?

but can't seem to make heads or tails of this. I have a pandas datafrom consisting of several rows, each of which are just lists of number and want to use seaborn.distplot to put them all on the same axis and just cycle through a standard color palette.

i'm currently trying:

palette = sns.color_palette()
sns.distplot(data_pandas, color = next(iter.cycle(palette)))

and getting:

Traceback (most recent call last):
  File "multiBx_single_plot.py", line 105, in <module>
    sns.distplot(data_pandas, color = next(iter.cycle(palette)))
AttributeError: 'builtin_function_or_method' object has no attribute 'cycle'

I've tried a few other methods, all of which fail. any help would be much appreciated. I don't want to have to assign colors manually...

cheers,

jake

Community
  • 1
  • 1
cancerconnector
  • 1,225
  • 2
  • 14
  • 21
  • 2
    `iter.cycle` -> `itertools.cycle` (`import itertools` beforehand.) – falsetru Mar 23 '16 at 04:14
  • Thanks for this. new error: ValueError: color kwarg must have one color per dataset – cancerconnector Mar 23 '16 at 04:17
  • 1
    You should not get angry to the down-voters, but instead, think why would this have happened. In Stackvoerflow you will only get downvotes if the question is badly stated/off topic. Read [ask], [mcve] and go to the [help] – Ander Biguri Mar 23 '16 at 20:21

1 Answers1

3

Here is how I solved the problem (with the help of @falsetru).

import seaborn as sns
import itertools


palette = itertools.cycle(sns.color_palette())

for i in range(r_sweep):
    sns.distplot(data[i], color = next(palette))

Hope that helps someone.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
cancerconnector
  • 1,225
  • 2
  • 14
  • 21
  • 1
    I'm glad you found the answer. For future reference: it is often polite to ping the person who solved your problem in a comment and ask them to add an answer. People help here just for "fake internet points", its good to give them to the right person when they deserve them ;). Keep up with the programming! – Ander Biguri Mar 23 '16 at 20:27
  • on that note: @falsetru - would you like to add an answer? – cancerconnector Mar 31 '16 at 14:02