Programing

씨본 플롯이 표시되지 않음

lottogame 2020. 6. 5. 08:01
반응형

씨본 플롯이 표시되지 않음


나는 매우 간단한 것을 잊어 버릴 것이라고 확신하지만 Seaborn과 일할 특정 음모를 얻을 수는 없습니다.

만약 내가한다면:

import seaborn as sns

그런 다음 matplotlib을 사용하여 평소대로 만드는 플롯은 Seaborn 스타일을 얻습니다 (배경에 회색 눈금 포함).

그러나 다음과 같은 예제 중 하나를 수행하려고하면

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 객체를 반환하지만 플롯은 표시되지 않습니다.

matplotlib이 제대로 작동하는 것처럼 보이고 Seaborn 스타일이 다른 matplotlib 플롯에 적용되기 때문에 약간 혼란 스럽지만 Seaborn 함수는 아무것도하지 않는 것 같습니다. 아무도 문제가 무엇인지 아는 사람이 있습니까?


seaborn을 사용하여 작성된 플롯은 일반 matplotlib 플롯과 같이 표시해야합니다. 이것은을 사용하여 수행 할 수 있습니다

plt.show()

matplotlib의 기능.

원래 seaborn ( sns.plt.show()) 에서 이미 가져온 matplotlib 객체를 사용하도록 솔루션을 게시 했지만 이것은 나쁜 습관으로 간주됩니다. 따라서 matplotlib.pyplot 모듈을 직접 가져 와서 플롯을

import matplotlib.pyplot as plt
plt.show()

IPython 노트북을 사용하는 경우 인라인 백엔드를 호출하여 각 플롯 후에 show를 호출 할 필요가 없습니다. 각각의 마법은

%matplotlib inline

나는이 질문에 상당히 규칙적으로 도달하고 내가 찾은 것을 찾는 데 항상 시간이 걸립니다.

import seaborn as sns
import matplotlib.pyplot as plt

plt.show()  # <--- This is what you are looking for

참고 : Python 2에서는 Python 3에서는 사용할 수 sns.plt.show()없지만 Python 3에서는 사용할 수 없습니다.

완전한 예

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Visualize C_0.99 for all languages except the 10 with most characters."""

import seaborn as sns
import matplotlib.pyplot as plt

l = [41, 44, 46, 46, 47, 47, 48, 48, 49, 51, 52, 53, 53, 53, 53, 55, 55, 55,
     55, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58,
     58, 59, 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 61,
     61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62,
     62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 65,
     65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, 66, 66,
     67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 69, 69, 69, 70, 70,
     70, 70, 71, 71, 71, 71, 71, 72, 72, 72, 72, 73, 73, 73, 73, 73, 73, 73,
     74, 74, 74, 74, 74, 75, 75, 75, 76, 77, 77, 78, 78, 79, 79, 79, 79, 80,
     80, 80, 80, 81, 81, 81, 81, 83, 84, 84, 85, 86, 86, 86, 86, 87, 87, 87,
     87, 87, 88, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 91, 91, 92,
     92, 93, 93, 93, 94, 95, 95, 96, 98, 98, 99, 100, 102, 104, 105, 107, 108,
     109, 110, 110, 113, 113, 115, 116, 118, 119, 121]

sns.distplot(l, kde=True, rug=False)

plt.show()

준다

enter image description here


혼란을 피하기 위해 (의견에 일부가있는 것처럼 보입니다). Jupyter를 사용한다고 가정합니다.

%matplotlib inline> 노트북 내부 에 줄거리를 표시합니다

sns.plt.show() > displays the plots OUTSIDE of the notebook

%matplotlib inline will OVERRIDE sns.plt.show() in the sense that plots will be shown IN the notebook even when sns.plt.show() is called.

And yes, it is easy to include the line in to your config:

Automatically run %matplotlib inline in IPython Notebook

But it seems a better convention to keep it together with imports in the actual code.


My advice is just to give a

plt.figure() and give some sns plot. For example

sns.distplot(data).

Though it will look it doesnt show any plot, When you maximise the figure, you will be able to see the plot.


This worked for me

import matplotlib.pyplot as plt
import seaborn as sns
.
.
.
plt.show(sns)

If you plot in IPython console (where you can't use %matplotlib inline) instead of Jupyter notebook, and don't want to run plt.show() repeatedly, you can start IPython console with ipython --pylab:

$ ipython --pylab     
Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.1 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: Qt5Agg

In [1]: import seaborn as sns

In [2]: tips = sns.load_dataset("tips")

In [3]: sns.relplot(x="total_bill", y="tip", data=tips) # you can see the plot now

To tell from the style of your code snippet, I suppose you were using IPython rather than Jupyter Notebook.

In this issue on GitHub, it was made clear by a member of IPython in 2016 that the display of charts would only work when "only work when it's a Jupyter kernel". Thus, the %matplotlib inline would not work.

I was just having the same issue and suggest you use Jupyter Notebook for the visualization.

참고URL : https://stackoverflow.com/questions/26597116/seaborn-plots-not-showing-up

반응형