2016-09-11 2 views
0
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のパッケージ)で実行すると、目的の結果が得られます。しかし、同じコードが(行を含めます。%matplotlibのインライン)Jupter QtConsoleで実行されたときに、私は次のエラーを取得:Jupyter QtPythonエラー

アウト:

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. 

私は何が起こっているのか分かりません。

答えて

0

多少の関連性...別のセルで次の行を実行していたため、私はjupyterノートブックを実行しているときに同じエラーが発生しました。

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

同じセルで両方を実行すると、画像が適切に表示されます。

Qtコンソールを使用しているので、マッピングをグリッドに割り当てるのに役立つかどうかを確認してください。

grid = grid.map(plt.hist, "tip_pct", bins=np.linspace(0, 40, 15)) 

documentation for FacetGridでも同じアプローチが使用されています。