【问题标题】:Additional keyword arguments in seaborn jointplotseaborn 联合图中的附加关键字参数
【发布时间】:2014-12-09 01:02:39
【问题描述】:

我试图找出 matplotlib 和 seaborn 绘图函数是如何关联的。特别是,我想知道哪些 pyplot 参数可以传递到函数seaborn.jointplot() 中的关键字字典marginal_kwsannot_kws

假设我们有 DataFrame data,列有 c0c1。我猜想joint_kws 接受来自pyplot.hexbin() 的参数,所以当我尝试用那里的参数调整外观时,它工作正常:

import seaborn as sns   
sns.jointplot('c0', 'c1', data=data,  kind='hex',
               joint_kws={'gridsize':100, 'bins':'log', 'xscale':'log', 'yscale':'log'})

然后我尝试使用来自pyplot.hist() 的参数log=True 在直方图轴上设置对数比例:

    sns.jointplot('c0', 'c1', data=data,  kind='hex',
                   joint_kws={'gridsize':100, 'bins':'log', 'xscale':'log', 'yscale':'log'}, 
                   marginal_kws={'log':True})

这会导致

TypeError: distplot() got an unexpected keyword argument 'log'

如何正确表达?

附:这个问题不是关于在 seaborn 中设置对数比例(我知道 JointGrid),而是关于将 matplotlib 参数作为一个整体传递给 seaborn 函数。

【问题讨论】:

  • 我可以看到您使用的是jointplot,但为什么distplot会出现错误?
  • 我没有深入研究源代码,但我认为jointplot 边缘的直方图是通过distplot 构造的。我还以为marginal_kws对应distplot中的{hist, kde, rug, fit}_kws,但好像不正确。

标签: python matplotlib seaborn


【解决方案1】:

关键字参数的字典被传递给distplot,它接受hist_kws 的字典。所以你必须做类似marginal_kws={'hist_kws': {'log': True}}的事情。话虽如此,jointplot 的共享日志轴仍然是一个令人头疼的问题,而且在调整您的代码时,我无法得到开箱即用的东西。不过,进行一些调整可能会使其正常工作。

尝试使用JointGrid directly 来避免这种复杂性也可能很有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-26
    • 2017-03-18
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 2016-05-03
    相关资源
    最近更新 更多