【问题标题】:Unexpected keyword error with lmplot inside a FacetGridFacetGrid 中的 lmplot 出现意外的关键字错误
【发布时间】:2020-04-20 02:45:28
【问题描述】:

尝试在 FacetGrid 中使用 lmplot 时遇到一个奇怪的错误。

我的代码:

from matplotlib import pyplot as plt
import seaborn as sns

tips = sns.load_dataset('tips')
g = sns.FacetGrid(data=tips, col='time', row='sex')
g.map(sns.lmplot, 'total_bill', 'tip')

我明白了:

TypeError: lmplot() 得到了一个意外的关键字参数“颜色”

【问题讨论】:

    标签: python data-visualization seaborn


    【解决方案1】:

    问题是lmplot() 已经带有FacetGrid(它是regplotFacetGrid 的组合,请参阅文档https://seaborn.pydata.org/generated/seaborn.lmplot.html#seaborn.lmplot),所以当你调用它时,这两者会发生冲突。如果您想绘制您的要求,只需在FacetGrid 中调用regplot()

    from matplotlib import pyplot as plt
    import seaborn as sns
    
    tips = sns.load_dataset('tips')
    g = sns.FacetGrid(data=tips, col='time', row='sex')
    g.map(sns.regplot, 'total_bill', 'tip')
    

    如果你坚持lmplot(),可以使用如下sn-p:

    g = sns.lmplot(x="total_bill", y="tip", row="sex", col="time", data=tips)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多