Jupyter QtPython错误

时间:2016-09-11 19:10:09

标签: matplotlib ipython seaborn

    import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns;

tips = sns.load_dataset('tips')
tips.head()

tips['tip_pct'] = 100 * tips['tip'] / tips['total_bill']
grid = sns.FacetGrid(tips, row="sex", col="time", margin_titles=True)
grid.map(plt.hist, "tip_pct", bins=np.linspace(0, 40, 15));

当我在Spyder IDE(Anaconda Navigator' s Package)中运行上述代码时,我得到了预期的结果。但是当在Jupter QtConsole中运行相同的代码(包括行:%matplotlib inline)时,我会收到以下错误:

输出:

ValueErrorTraceback (most recent call last)
<ipython-input-47-c7ea1bbe0c80> in <module>()
----> 1 grid.map(plt.hist, "tip_pct", bins=np.linspace(0, 40, 15));

/Users/waqas/anaconda/lib/python3.5/site-packages/seaborn/axisgrid.py in map(self, func, *args, **kwargs)
701 
702             # Get the current axis
--> 703             ax = self.facet_axis(row_i, col_j)
704 
705             # Decide what color to plot with

/Users/waqas/anaconda/lib/python3.5/site-packages/seaborn/axisgrid.py in facet_axis(self, row_i, col_j)
832 
833         # Get a reference to the axes object we want, and make it active
--> 834         plt.sca(ax)
835         return ax
836 

/Users/waqas/anaconda/lib/python3.5/site-packages/matplotlib/pyplot.py in sca(ax)
905             m.canvas.figure.sca(ax)
906             return
--> 907     raise ValueError("Axes instance argument was not found in a figure.")
908 
909 

ValueError: Axes instance argument was not found in a figure.

我不知道发生了什么。

1 个答案:

答案 0 :(得分:1)

有点相关......我在运行jupyter笔记本时遇到了同样的错误,因为我在不同的单元格中运行了以下行。

this.ts = tsService.getTs();

一旦我在同一个单元格中运行它们,图像就会正确显示。

由于你正在使用Qt控制台,看看它是否有助于将你的映射分配给网格。

g = sns.FacetGrid(data=titanic,col='sex')
g.map(plt.hist,'age')

您会在documentation for FacetGrid中看到相同的方法。