首页 > 解决方案 > 为什么在 Spyder 中使用 sns.set_palette 会出错?

问题描述

我正在尝试使用以下方法在 Spyder 的 Python 脚本中设置 seaborn 调色板:

import seaborn as sns
sns.set_palette("Reds")

作为参数传递的调色板并不重要,我总是得到以下错误:

Traceback (most recent call last):

  File "<ipython-input-20-efc46ee41836>", line 1, in <module>
    sns.set_palette("Reds")

  File "c:\users\lucas-magalhaes\anaconda3\lib\site-packages\seaborn\rcmod.py", line 550, in set_palette
    mpl.rcParams['axes.prop_cycle'] = cyl

  File "c:\users\lucas-magalhaes\anaconda3\lib\site-packages\matplotlib\__init__.py", line 679, in __setitem__
    raise ValueError(f"Key {key}: {ve}") from None

ValueError: Key axes.prop_cycle: object was not a string or Cycler instance: cycler('color', [(0.9950634371395617, 0.8596539792387543, 0.7986620530565167), (0.9882352941176471, 0.6866743560169165, 0.5778854286812765), (0.9865897731641676, 0.5067281814686659, 0.38123798539023457), (0.9570011534025374, 0.3087120338331411, 0.22191464821222606), (0.8370472895040368, 0.13394848135332565, 0.13079584775086506), (0.6663437139561708, 0.06339100346020761, 0.08641291810841982)])

这在 Jupyter 中运行良好,但在 Spyder 中却不行。知道为什么吗?

标签: pythonmatplotlibseabornspydercolor-palette

解决方案


推荐阅读