2

I installed seaborn, but when I do the example from the Seaborn website, I get StopIteration message, how do I fix it?

import seaborn as sns penguins = sns.load_dataset("penguins") sns.histplot(data=penguins, x="flipper_length_mm")

StopIteration Traceback (most recent call last) Cell In [33], line 1 ----> 1 sns.histplot(data=penguins, x="flipper_length_mm")

image

Ray Hu
  • 31
  • 2
  • I recommend using the [Anaconda Distribution](https://www.anaconda.com/products/individual), it's likely to make your life much easier. All packages are installed as precompiled binaries. [Package List](https://docs.anaconda.com/anaconda/packages/py3.8_win-64/). **If you are using Anaconda, do not use `pip` to install packages that exist within the `conda` ecosystem.** Use `conda install package`. Only use `pip` if the package is not available with `conda install`. Using `pip` can potentially wreck your installation because `pip` and `conda` do not manage dependencies in the same way. – Trenton McKinney Oct 18 '22 at 18:32
  • Unfortunately, this is a bug in `matplotlib` that is (uniquely?) affecting `seaborn`. See the issue ellhe-blaster linked to below. The recommendation is to downgrade to `matplotlib` 3.6.0, e.g. `conda install -c conda-forge matplotlib=3.6.0`. This has resolved the issue for me (for now) and I hope it works for you, too. – dmn Oct 20 '22 at 13:34

2 Answers2

2

The problem seem to be in the default color definition function. If you specify a color you can skip the error:

sns.histplot(data=penguins, x="flipper_length_mm", color='blue')

That solved the problem for me, hope it does for you as well. Cheers

halfelf
  • 9,737
  • 13
  • 54
  • 63
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 23 '22 at 11:36
2

The problem is with matplotlib==3.6.1

You have 2 variants:

  1. Upgrade matplotlib up to 3.6.2 version via
pip install matplotlib --upgrade
  1. Downgrade matplotlib to 3.6.0 version via
pip install matplotlib==3.6.0 --force-reinstall

Both variants worked for me.
Here is the same issue on GitHub: https://github.com/mwaskom/seaborn/issues/3072

Alex
  • 316
  • 2
  • 5