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));

When I run the above code in Spyder IDE (Anaconda Navigator's Package), I get the desired results. But when the same code is run in Jupter QtConsole (including the line: %matplotlib inline) I get the following errors:

Out:

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.

I don't know what's going on.

1 Answer 1

1

Somewhat related...I was getting the same error when running jupyter notebook because I was running the following lines in separate cells.

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

Once I ran them both in the same cell the image displayed properly.

Since you're using Qt console see if it helps to assign your mapping to grid.

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

You'll see the same approach is used in the documentation for FacetGrid.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.