首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ValueError:提供“c”kwarg或“color”kwarg,但不能同时提供这两个;它们不同,但功能重叠。

ValueError:提供“c”kwarg或“color”kwarg,但不能同时提供这两个;它们不同,但功能重叠。
EN

Stack Overflow用户
提问于 2016-10-20 04:59:42
回答 1查看 1.3K关注 0票数 2

我正在尝试使用下面的代码在一个大图中创建多个seaborn regplot:

代码语言:javascript
复制
%matplotlib notebook
import seaborn as sns
from itertools import combinations
import matplotlib.pyplot as plt

pairs = list(combinations(pandas_transformed.drop(['prediction'],axis=1).columns, 2))
col = pandas_transformed.prediction.map({0: [1,0,0], 1:[0,1,0]})

fig, axes = plt.subplots(len(pairs) // 3, 3, figsize=(12, 108))
for i, pair in enumerate(pairs):
    d = pandas_transformed[list(pair)]
    ax = axes[i // 3, i % 3]
    #d.plot.scatter(*pair, ax=ax, c=col, linewidths=0, s=2, alpha = 0.7)
    sns.regplot(x = pair[0], y = pair[1], data = d, fit_reg = False, ax = ax, x_jitter = True,\
             scatter_kws={"c": col}, line_kws = {})

fig.tight_layout()

但是,我得到了以下错误:

代码语言:javascript
复制
ValueErrorTraceback (most recent call last)
<ipython-input-12-ae2676825628> in <module>()
     12     ax = axes[i // 3, i % 3]
     13     #d.plot.scatter(*pair, ax=ax, c=col, linewidths=0, s=2, alpha = 0.7)
---> 14     sns.regplot(x = pair[0], y = pair[1], data = d, fit_reg = False, ax = ax, x_jitter = True,             scatter_kws={"c": col}, line_kws = {})
     15 
     16 fig.tight_layout()

/usr/local/lib/python2.7/dist-packages/seaborn/linearmodels.pyc in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
    777     scatter_kws["marker"] = marker
    778     line_kws = {} if line_kws is None else copy.copy(line_kws)
--> 779     plotter.plot(ax, scatter_kws, line_kws)
    780     return ax
    781 

/usr/local/lib/python2.7/dist-packages/seaborn/linearmodels.pyc in plot(self, ax, scatter_kws, line_kws)
    328         # Draw the constituent plots
    329         if self.scatter:
--> 330             self.scatterplot(ax, scatter_kws)
    331         if self.fit_reg:
    332             self.lineplot(ax, line_kws)

/usr/local/lib/python2.7/dist-packages/seaborn/linearmodels.pyc in scatterplot(self, ax, kws)
    357 
    358             x, y = self.scatter_data
--> 359             ax.scatter(x, y, **kws)
    360         else:
    361             # TODO abstraction

/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
   1817                     warnings.warn(msg % (label_namer, func.__name__),
   1818                                   RuntimeWarning, stacklevel=2)
-> 1819             return func(ax, *args, **kwargs)
   1820         pre_doc = inner.__doc__
   1821         if pre_doc is None:

/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_axes.pyc in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   3787                 facecolors = co
   3788             if c is not None:
-> 3789                 raise ValueError("Supply a 'c' kwarg or a 'color' kwarg"
   3790                                  " but not both; they differ but"
   3791                                  " their functionalities overlap.")

ValueError: Supply a 'c' kwarg or a 'color' kwarg but not both; they differ but their functionalities overlap.

这个错误真的很让人困惑。因为我只提供scatter_kws={"c": col},所以默认颜色是None。和https://seaborn.github.io/generated/seaborn.regplot.html#seaborn.regplot上的每一份海运文档

代码语言:javascript
复制
color : matplotlib color
Color to apply to all plot elements; will be superseded by colors passed in scatter_kws or line_kws.

我不明白为什么我会得到这个错误。有谁知道吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2016-10-21 03:25:52

这可以很好地工作,设置绘图颜色并通过色彩映射表传递到散点:

代码语言:javascript
复制
import seaborn as sns
tips = sns.load_dataset("tips")
sns.regplot(x='total_bill', y='tip',data=tips, 
            scatter_kws={'c':sns.color_palette()}, 
            color='red')
plt.show()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40141445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档