【发布时间】:2019-02-26 12:30:25
【问题描述】:
我已经找到了一个处理类似主题的条目,但该建议在这里不起作用。
How can I use seaborn without changing the matplotlib defaults?
如果我错过了什么,我会感谢每一个链接。
我想在用 seaborn 创建一个图之后用 matplotlib 创建一个图。但是,seaborn 的设置似乎会影响 matplotlib 的外观(我意识到 seaborn 是 matplotlib 的扩展)。即使我清除、关闭情节等也会发生这种情况。
sns.reset_orig()
plt.clf()
plt.close()
完整示例代码:
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()
seaborn 的情节看起来总是一样的: seaborn plot
但是 matplotlib 绘图的外观不同。没有在前面创建 seaborn 情节的正常人: mpl plot normal
如果使用显示的代码,它会如何变化: mpl with sns in front
我该如何阻止这种行为,避免 seaborn 影响其他地块?
【问题讨论】:
标签: python matplotlib plot seaborn