如何在seaborn.despine中使用dictonary进行偏移?

时间:2017-09-13 13:34:00

标签: python matplotlib seaborn

我试图单独调节脊柱的偏移量。例如,我希望左侧脊柱的距离大于底部的距离。 在文档中,它说offset-keyword也接受字典;但是,我收到一条错误消息,我不知道这意味着什么。令人惊讶的是,我找不到任何关于dictonary-offset-comination的例子。

  

http://seaborn.pydata.org/generated/seaborn.despine.html

     

offset:int或dict,可选   绝对距离(以磅为单位)应将脊椎移离轴线(负值向内移动脊柱)。单个值适用于   所有的刺; dict可用于设置每边的偏移值。

这是我无法解决的示例代码:

sns.despine(ax=ax, trim=True, offset={'left':10,'right':10,'top':20,'bottom':13})

这是错误信息:

TypeError: unsupported operand type(s) for *: 'dict' and 'int'

总结: 我想知道如何单独设置每个脊柱的偏移量;最好是用seaborn.despine。 (关于错误告诉我的内容的其他解释也将受到赞赏。)

谢谢: - )

修改
我尝试了ImportanceOfBeingErnest的示例代码(仅添加'ticks'作为样式),但仍然得到相同的结果。任何想法为什么会发生这种情况?

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style('ticks') 
fig,ax=plt.subplots()
ax.plot([1,2,3])

sns.despine(ax=ax, trim=True, offset={'left':10,'right':10,'top':20,'bottom':13})

plt.show()

显示情节,但刺不会发生变化。

TypeError: unsupported operand type(s) for *: 'dict' and 'int'

resulting plot

1 个答案:

答案 0 :(得分:0)

这是我的问题的解决方案。是的,正如ImportanceOfBeingErnestPaul H指出的那样,使用的seaborn版本确实存在问题。

基本上,归结为我没有正确使用anaconda环境 为了澄清我的具体问题:我使用了anaconda环境安装了最新的seaborn版本(0.8.1):conda install -c conda-forge seaborn
但是,我并没有在环境中专门安装spyder(我的主IDE)。我可以从环境中开始spyder;因此我从未质疑过它。好吧,事实证明spyder然后在其他地方寻找模块,我有一个较旧的seaborn版本(0.7.1)。这在以前从来就不是问题,但我现在很高兴知道。我在环境中安装了spyder,现在它在seaborn.despine中寻找正确的模块和偏移量就可以了:-) conda install -c anaconda spyder
然后从jrinker's answer
conda update -n $ENV_NAME spyder