Search code examples
pythonplotgraphseabornfacet-grid

How do I implement the FacetGrid function in my Python codes?


I am new to Python and below is an extract of some Python codes in my Jupyter Notebook:

import pandas as pd
import matplotlib.pyplot as plt

import numpy as np
import seaborn as sns
sns.set(style="darkgrid")
FacetGrid.set(yticks=np.arange(0, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000))
import numpy as np
%matplotlib inline

plt.rcParams['figure.figsize']=(20,20)

When I run these codes, I get the following error: NameError: name 'FacetGrid' is not defined

I did a search and found the following: Change number of x-axis ticks in seaborn plots

However, I cannot seem to be able to implement it correctly in my codes.I need the FacetGrid function to manually specify the ticks values on the y-axis of a seaborn stripplot.

How do I correct for this?


Solution

  • The main point is that you need to work with an instance of FacetGrid not the class itself. Also, you need to define your numpy array for the ticklabels correctly.

    Here is an example based on your code:

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set(style="darkgrid")
    
    data = pd.DataFrame({})
    g = sns.FacetGrid(data, size=20)
    
    yticks = np.arange(0,8500,500)
    g.set(yticks=yticks)
    
    plt.show()