Use seaborn with custom matplotlib styles
See original GitHub issueStackoverflow answers here and here, and the docsting here (and I assume many other places) incorrectly point out that using import seaborn.apionly as sns or sns.reset_orig() can prevent seaborn from rewriting custom rc parameters.
In truth, this seems to just revert to the matplotlib defaults.
Ideally I would like to get the results provided by the following code, without having to insert a call to my custom parameters in between the seaborn import and the plot call
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="ticks")
plt.style.use(u'ggplot')
# Load the example dataset for Anscombe's quartet
df = sns.load_dataset("anscombe")
# Show the results of a linear regression within each dataset
sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=df,
col_wrap=2, ci=None, palette="muted", size=4,
scatter_kws={"s": 50, "alpha": 1})
plt.show()
None of the following alternatives produce a comparable result:
I.
import matplotlib.pyplot as plt
plt.style.use(u'ggplot')
import seaborn.apionly as sns
sns.set(style="ticks")
# Load the example dataset for Anscombe's quartet
df = sns.load_dataset("anscombe")
# Show the results of a linear regression within each dataset
sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=df,
col_wrap=2, ci=None, palette="muted", size=4,
scatter_kws={"s": 50, "alpha": 1})
plt.show()
II.
import matplotlib.pyplot as plt
plt.style.use(u'ggplot')
import seaborn as sns
sns.reset_orig()
sns.set(style="ticks")
# Load the example dataset for Anscombe's quartet
df = sns.load_dataset("anscombe")
# Show the results of a linear regression within each dataset
sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=df,
col_wrap=2, ci=None, palette="muted", size=4,
scatter_kws={"s": 50, "alpha": 1})
plt.show()
III.
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="ticks")
# Load the example dataset for Anscombe's quartet
df = sns.load_dataset("anscombe")
# Show the results of a linear regression within each dataset
sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=df,
col_wrap=2, ci=None, palette="muted", size=4,
scatter_kws={"s": 50, "alpha": 1})
plt.style.use(u'ggplot')
plt.show()
IV.
import matplotlib.pyplot as plt
import seaborn.apionly as sns
sns.set(style="ticks")
# Load the example dataset for Anscombe's quartet
df = sns.load_dataset("anscombe")
# Show the results of a linear regression within each dataset
sns.lmplot(x="x", y="y", col="dataset", hue="dataset", data=df,
col_wrap=2, ci=None, palette="muted", size=4,
scatter_kws={"s": 50, "alpha": 1})
plt.style.use(u'ggplot')
plt.show()
Can you help me out? I write wrappers for my plotting functions which I call from PythonTeX or other analysis scripts. To continue using the initial code sequence I would need to mess up my API for all functions that somewhere use any module that imports seaborn, and pass them matplotlibrc as an argument all the way down.
It would be really great if seaborn had the option to play nice and not touch matplotlibrc.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (3 by maintainers)

Top Related StackOverflow Question
@mmagnuski thank you so much for the pointer. Indeed, the version bump fixed this. As a positive side-effect of my run-in with this bug, I have now added
=dev-python/seaborn-0.7.1to the Gentoo package tree.@TheChymera Yes, I was able to replicate your problems on
0.7.0but not after upgrading to0.7.1. One of the things that changed in0.7.1is that seaborn saves the matplotlib rc params at import and inapionlyapplies them back in the end.