The method seaborn.set_theme() does not work

Viewed 7258

In a jupyter notebook, I run

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import scipy.stats as stat 

and then in another cell, I run sns.set_theme(), and I get the following error

AttributeError: module 'seaborn' has no attribute 'set_theme'.

But it should according to https://seaborn.pydata.org/tutorial/aesthetics.html

Why is that?

2 Answers

sns.set_theme() function was added in v0.11, and you are likely using an older version. To install the v0.11.0 or v0.11.1 conda install seaborn=0.11

The functionality previously existed under the name sns.set, and it continues to on newer versions, so updating is not strictly necessary. If you would like the functionality on an older version of seaborn, you can run seaborn.set(), which is an alias for sns.set_theme() in 0.11+.

seaborn.set_theme was added in version 0.11.0; if you are on an earlier version, it will not be available. But it is a new name for the previously existing seaborn.set function, which remains available as an alias.

Updating your seaborn will solve the problem, but there were some important API changes in seaborn 0.11.0 to be aware of. Therefore, I would not recommend blindly updating just to make the set_theme name available. (I do recommend updating to version 0.11, but you should take time to understand how the API changes impact your code first).

Related