question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I’m trying to plot this basic DataFrame with a FacitGrid and running into this value error. Windows 7 x64, Python 2.7

print sns.__version__ 0.3.1
print pd.__version__ 0.13.1
print np.__version__ 1.7.1
print matplotlib.__version__ 1.3.0
import numpy as np
import pandas as pd
import seaborn as sns
from scipy import stats
import matplotlib as mpl
import matplotlib.pyplot as plt

In [2]:

sns.set(style="white")

np.random.seed(sum(map(ord, "axis_grids")))

In [3]:

df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],

                 'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],

                 'C' : randn(8), 'D' : randn(8)})

In [4]:

df

Out[4]:
    A   B   C   D
0   foo     one     0.805998    1.520340
1   bar     one     -1.519987   -1.845697
2   foo     two     -1.209843   -0.110755
3   bar     three   0.033920    0.569092
4   foo     two     0.138512    -0.341390
5   bar     two     -1.945447   -0.505211
6   foo     one     -0.933446   -0.161730
7   foo     three   0.815080    -0.755682

8 rows × 4 columns
In [5]:

g = sns.FacetGrid(df, col='A', row='B')

In [6]:

g.map(plt.scatter, 'C', 'D')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-b16344b8ad2e> in <module>()
----> 1 g.map(plt.scatter, 'C', 'D')

D:\Python27\lib\site-packages\seaborn-0.3.1-py2.7.egg\seaborn\axisgrid.pyc in map(self, func, *args, **kwargs)
    291 
    292             # Get the current axis
--> 293             ax = self.facet_axis(row_i, col_j)
    294 
    295             # Decide what color to plot with

D:\Python27\lib\site-packages\seaborn-0.3.1-py2.7.egg\seaborn\axisgrid.pyc in facet_axis(self, row_i, col_j)
    415 
    416         # Get a reference to the axes object we want, and make it active
--> 417         plt.sca(ax)
    418         return ax
    419 

D:\Python27\lib\site-packages\matplotlib\pyplot.pyc in sca(ax)
    780             m.canvas.figure.sca(ax)
    781             return
--> 782     raise ValueError("Axes instance argument was not found in a figure.")
    783 
    784 

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

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

24reactions
mwaskomcommented, May 9, 2014

It sounds like for the backend you’re using you’ll need to keep the call to the FacetGrid constructor and the call to g.map() in the same In cell/line.

0reactions
cbr-analyticscommented, May 20, 2018

@mwaskom , Thanks, this helped in 2018! @mwaskom

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: Axes instance argument was not found in a figure ...
I encountered this similar issue when running a Jupyter Notebook. My solution involved: Restart the notebook. Re-run the imports %matplotlib ...
Read more >
Solved: error in python - Experts Exchange
Find answers to error in python from the expert community at Experts ... ValueError: Axes instance argument was not found in a figure...
Read more >
Seaborn FacetGrid "Axes instance argument not found"
ValueError : Axes instance argument was not found in a figure. ``` Sounds harmless but it is a surprising result. Not sure why...
Read more >
Re: [matplotlib-devel] An easier way to create figure and group ...
Gcf.set_active(ax.figure.canvas.manager) > ax.figure.sca(ax) > return > raise ValueError("Axes instance argument was not found in a figure.
Read more >
Source code for matplotlib.pyplot
QtCore' in sys.modules and not backend == 'Qt4Agg': import PyQt4. ... raise ValueError("Axes instance argument was not found in a figure.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found