当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Seaborn plot is not showing

问题描述:

This question already has an answer here:

  • Seaborn plots not showing up

    3 answers

网友答案:

As mentioned above in the other answer, running in IPython will allow you to see it, but that isn't the only way.

The last line of your method returns a FacetGrid object, which is silently discarded after your method exits, which is why you are seeing nothing other than the warning which is produced. You will need to do something with this object (IPython automatically "prints" it when it is produced).

Change your method like so:

def run_example(self):
    sns.set(color_codes=True)
    np.random.seed(sum(map(ord, "regression")))
    tips = sns.load_dataset("tips")
    sns.lmplot(x="size", y="tip", data=tips, x_estimator=np.mean).fig.show()

Now your example will open a graphical window showing the figure

If you want to save it instead, change that last line to

sns.lmplot(x="size", y="tip", data=tips, x_estimator=np.mean).savefig("testing.png")

This sort of behavior is typical of matplotlib and thus seaborn which is built on top of matplotlib. You will have to specify what needs to be done with graphics objects (the %matplotlib inline call in IPython is actually telling IPython to catch these objects and display them).

分享给朋友:
您可能感兴趣的文章:
随机阅读: