Seaborn配置隐藏默认的matplotlib [英] Seaborn configuration hides default matplotlib

查看:249
本文介绍了Seaborn配置隐藏默认的matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Seaborn 提供了一些图形,这些图形对于科学界来说非常有趣数据表示. 因此,我开始使用这些Seaborn图形以及其他自定义的matplotlib图. 问题是一旦我这样做:

Seaborn provides of a handful of graphics which are very interesting for scientifical data representation. Thus I started using these Seaborn graphics interspersed with other customized matplotlib plots. The problem is that once I do:

import seaborn as sb

此导入似乎为全局设置了seaborn的图形参数,然后该导入下方的所有matplotlib图形都获得了seaborn参数(它们具有灰色背景,带有线的更改等).

This import seems to set the graphic parameters for seaborn globally and then all matplotlib graphics below the import get the seaborn parameters (they get a grey background, linewithd changes, etc, etc).

因此,有答案解释如何使用matplotlib配置生成海图,但是我想要的是在同时使用两个库时保持matplotlib配置参数不变,同时能够在需要时生成原始海图.

In SO there is an answer explaining how to produce seaborn plots with matplotlib configuration, but what I want is to keep the matplotlib configuration parameters unaltered when using both libraries together and at the same time be able to produce, when needed, original seaborn plots.

推荐答案

截至

As of seaborn version 0.8 (July 2017) the graph style is not altered anymore on import:

导入seaborn时,将不再应用默认的[seaborn]样式.现在必须显式调用 set() set_style() set_context() .相应地,已弃用seaborn.apionly模块.

The default [seaborn] style is no longer applied when seaborn is imported. It is now necessary to explicitly call set() or one or more of set_style(), set_context(), and set_palette(). Correspondingly, the seaborn.apionly module has been deprecated.

您可以使用plt.style.use()选择任何情节的样式.

You can choose the style of any plot with plt.style.use().

import matplotlib.pyplot as plt
import seaborn as sns

plt.style.use('seaborn')     # switch to seaborn style
# plot code
# ...

plt.style.use('default')     # switches back to matplotlib style
# plot code
# ...


# to see all available styles
print(plt.style.available)

详细了解 plt.style() .

这篇关于Seaborn配置隐藏默认的matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆