The AttributeError: FacetGrid object has no attribute get_figure error occurs when you tried to save the plot in seaborn using the get_figure() function. The error clearly says that the FaceGrid object does not have any attribute get_figure. In this short article, we will learn how we can solve the error and how we can save the plot as an image in the seaborn module. Moreover, we will also list the possible reasons for getting this error.

AttributeError: FacetGrid object has no attribute get_figure
Sometimes, when you are working with the seaborn module and want to save the plot as an image, you face AttributeError: FacetGrid object has no attribute get_figure error. This error can be solved by replacing the get_figure() function with savefig() function.
Let us assume that we want to plot a scattered plot in Seaborn and want to save the plot as a png file. The following code will produce an error as it is using the get_figure() function.
# importing the data and module
import seaborn as sns
tips = sns.load_dataset("tips")
# plotting scattered plot
scattered_plot = sns.relplot(
data = tips,
x = 'total_bill',
y = 'tip',
kind = 'scatter'
)
# saving the plot
scattered_plot.get_figure('myScattered.png')
Output:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[10], line 14
6 scattered_plot = sns.relplot(
7 data = tips,
8 x = 'total_bill',
9 y = 'tip',
10 kind = 'scatter'
11 )
13 # saving the plot
---> 14 scattered_plot.get_figure('myScattered.png')
AttributeError: 'FacetGrid' object has no attribute 'get_figure'
The error occurs because we are trying to save the plot using the get_figure() method which is not allowed.
Solution-1: Saving seaborn plot using savefig() method
As we discussed earlier that if you are facing the error because you wanted to save the plot as a png file using the get_figure() method, you face the error. The easiest way to solve the error is to replace the get_figure function with the savefig method as shown below:
# importing the data and module
import seaborn as sns
tips = sns.load_dataset("tips")
# plotting scattered plot
scattered_plot = sns.relplot(
data = tips,
x = 'total_bill',
y = 'tip',
kind = 'scatter'
)
# saving the plot
scattered_plot.savefig('myScattered.png')
Output:
Now when you check the directory, you will notice that the following new image has been added to the directory.

If you want to show the plot inside the Jupyter Notebook without saving then you need to remove the saving part from your code as shown below:
# importing the data and module
import seaborn as sns
tips = sns.load_dataset("tips")
# plotting scattered plot
scattered_plot = sns.relplot(
data = tips,
x = 'total_bill',
y = 'tip',
kind = 'scatter'
)
Output:

Hopefully, you will no longer get the error.
Solution-2: Updating the Seaborn module
Sometimes, the error can also occur because of using an old version of the seaborn module. The get_figure() method was added to the seaborn module version 0.9.0, so if you are using an older version you need to update it.
You can use the following commands to upgrade the Seaborn module
# for pip users
pip install seaborn --upgrade
# for jupyter notebook users
!pip install seabron --upgrade
# anaconda users
conda install seabron --upgrade
Once, you have the updated version of the Seaborn module, you will no longer get the error.
Reasons for getting AttributeError: FacetGrid object has no attribute get_figure
The error “AttributeError: FacetGrid object has no attribute get_figure” occurs when you try to access the get_figure()
method of a FacetGrid object but it is not present in the object. This can happen due to several reasons:
- Typo: You might have made a typing error while calling the method. Make sure you have spelled the method name correctly.
- Outdated library version: The
get_figure()
method was added to the FacetGrid class in version 0.9.0 of the Seaborn library. If you are using an older version, the method may not be available. Try updating the library to the latest version. - Incorrect object type: It is possible that you have mistakenly called the
get_figure()
method on a different object that does not have this method. Make sure you are calling the method on a FacetGrid object. - Invalid input arguments: The error can also occur if you pass invalid input arguments to the
FacetGrid()
function. Make sure you have passed the correct arguments to the function. - Data issues: The error can also occur if there are issues with the data being plotted. Make sure that the data is in the correct format and does not contain any missing or invalid values.
- Memory issues: If you are working with large datasets, it is possible that your system is running out of memory, which can cause this error. Try reducing the size of the data or using a more powerful system.
Summary
In this short article, we discussed the reasons for getting AttributeError: FacetGrid object has no attribute get_figure error and we solved the error using various methods. We learned how we can save a plot in the Seaborn module as a png file.
Related issues
- ImportError: Missing optional dependency openpyxl
- [Solved] IndexError: string index out of range in Python
- AttributeError: ‘DataFrame’ object has no attribute ‘ix’ [Solved]