Seaborn地块未显示 [英] Seaborn plots not showing up

查看:59
本文介绍了Seaborn地块未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定我忘记了一些非常简单的东西,但是我无法获得某些与Seaborn合作的计划.

I'm sure I'm forgetting something very simple, but I cannot get certain plots to work with Seaborn.

如果我这样做:

import seaborn as sns

然后,我通常使用matplotlib创建的任何图都将获得Seaborn样式(背景为灰色网格).

Then any plots that I create as usual with matplotlib get the Seaborn styling (with the grey grid in the background).

但是,如果我尝试执行以下示例之一,例如:

However, if I try to do one of the examples, such as:

In [1]: import seaborn as sns

In [2]: sns.set()

In [3]: df = sns.load_dataset('iris')

In [4]: sns.pairplot(df, hue='species', size=2.5)
Out[4]: <seaborn.axisgrid.PairGrid at 0x3e59150>

pairplot函数返回一个PairGrid对象,但该图未显示.

The pairplot function returns a PairGrid object, but the plot doesn't show up.

我有点困惑,因为matplotlib似乎运行正常,并且Seaborn样式已应用于其他matplotlib图,但是Seaborn函数似乎没有任何作用.有人知道可能是什么问题吗?

I'm a little confused because matplotlib seems to be functioning properly, and the Seaborn styles are applied to other matplotlib plots, but the Seaborn functions don't seem to do anything. Does anybody have any idea what might be the problem?

推荐答案

使用seaborn创建的图需要像普通的matplotlib图一样显示. 可以使用

Plots created using seaborn need to be displayed like ordinary matplotlib plots. This can be done using the

plt.show()

matplotlib的功能.

function from matplotlib.

最初,我发布了使用已经从seaborn(sns.plt.show())导入的matplotlib对象的解决方案,但是这被认为是不好的做法.因此,只需直接导入 matplotlib.pyplot 模块并使用

Originally I posted the solution to use the already imported matplotlib object from seaborn (sns.plt.show()) however this is considered to be a bad practice. Therefore, simply directly import the matplotlib.pyplot module and show your plots with

import matplotlib.pyplot as plt
plt.show()

如果使用IPython笔记本,则可以调用内联后端,以消除在每次绘制后调用show的必要性.各自的魔力是

If the IPython notebook is used the inline backend can be invoked to remove the necessity of calling show after each plot. The respective magic is

%matplotlib inline

这篇关于Seaborn地块未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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