Seaborn地块未显示

编程入门 行业动态 更新时间:2024-10-12 16:25:09
本文介绍了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地块未显示

本文发布于:2023-05-29 03:38:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/335891.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地块   Seaborn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!