I have already found an entry that deals with a similar topic, but the suggestion doesn't work here.
How can I use seaborn without changing the matplotlib defaults?
If I missed something I am grateful for every link.
I want to create a plot with matplotlib after having created a plot with seaborn. However, the settings of seaborn seem to affect the matplotlib appearance (I realize that seaborn is an extension of matplotlib). This happens even though I clear, close the plot etc with.
sns.reset_orig()
plt.clf()
plt.close()
Complete example code:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# data
df = pd.DataFrame(np.array([[1, 1], [2, 2], [3, 3]]),columns=['x', 'y'])
###### seaborn plot #######
fig=sns.JointGrid(x=df['x'],
y=df['y'],
)
#fill with scatter and distribution plot
fig = fig.plot_joint(plt.scatter, color="b")
fig = fig.plot_marginals(sns.distplot, kde=False, color="b")
#axis labels
fig.set_axis_labels('x','y')
#set title
plt.subplots_adjust(top=0.92)
title='some title'
fig.fig.suptitle(title)
#clear and close figure
sns.reset_orig()
plt.clf()
plt.close()
###### matplotlib plot #######
#define data to plot
x = df['x']
y = df['y']
#create figure and plot
fig_mpl, ax = plt.subplots()
ax.plot(x,y,'.')
ax.grid(True)
ax.set_xlabel('x')
ax.set_ylabel('y')
title='some title'
ax.set_title(title)
plt.close()
The seaborn plot always looks the same: seaborn plot
But the apperance of the matplotlib plot differs. The normal one without creating a seaborn plot in front: mpl plot normal
and how it changes if using the shown code: mpl with sns in front
how do I stop this behaviour, avoid the seaborn influencing the other plots?
When you import seaborn the default styling is changed.
You can change the style that matplotlib applies to plots with the plt.style.use
command.
To get a list of available styles you can use plt.style.available
. To change back to the classic matplotlib style you'll want to use plt.style.use('classic')
.