繁体   English   中英

避免对Matplotlib积图产生重大影响

[英]avoid seaborn influencing matplotlib plots

我已经找到了涉及类似主题的条目,但是该建议在这里不起作用。

如何在不更改matplotlib默认值的情况下使用seaborn?

如果我错过了一些事情,我对每个链接都深表感谢。

我想用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()

海上情节总是看起来一样: 海上情节

但是matplotlib图的外观不同。 前面没有创建海洋图的普通图: mpl图正常

以及如何使用显示的代码进行更改: mpl,前面带有sns

我该如何停止这种行为,以免对其他地块产生深远的影响?

导入seaborn时,将更改默认样式。

您可以使用plt.style.use命令更改matplotlib适用于绘图的plt.style.use

要获取可用样式的列表,可以使用plt.style.available 要改回经典的matplotlib样式,您需要使用plt.style.use('classic')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM