0

I am trying to regulate the offset of the spines individually. For example I would like to have a bigger distance on the left spine than on the bottom one. In the documentation it says the offset-keyword also accepts a dictionary; however, I get an error message and I have no clue what it means. Surprisingly, I couldn't find any examples for the dictonary-offset-comination.

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

offset : int or dict, optional Absolute distance, in points, spines should be moved away from the axes (negative values move spines inward). A single value applies to all spines; a dict can be used to set offset values per side.

That's my not-working example code:

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

That's is the error message:

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

Summed up: I would like to know how to set the offset for each spine individually; preferably with seaborn.despine. (Additional explanations about what the error tells me would be appreciated as well.)

Thanks :-)

Edit:
I tried the example code from ImportanceOfBeingErnest (only added 'ticks' as style), but still get the same result. Any ideas why that happens?

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()

The plot gets displayed, but the spines don't change at all.

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

resulting plot

Community
  • 1
  • 1
eeefa
  • 1
  • 2

1 Answers1

0

Here is the solution to my problem. Yes, as ImportanceOfBeingErnest and Paul H pointed out it indeed was a problem with the used seaborn version.

Basically, it boils down to me not using the anaconda environment properly.
To clarify what my specific problem was: I used an anaconda environment where I installed the latest seaborn version (0.8.1): conda install -c conda-forge seaborn
However, I didn't specifically install spyder (my main IDE) in the environment. I could start spyder from within the environment though; therefore I never questioned it. Well, it turned out that spyder then looked for modules somewhere else where I had an older seaborn version (0.7.1). This has never been a problem before, but I am glad to know now. I installed spyder within the environment and now it looks for the correct modules and the offset in seaborn.despine works just fine :-) conda install -c anaconda spyder
and then from jrinker's answer:
conda update -n $ENV_NAME spyder

eeefa
  • 1
  • 2