Python Forum

Full Version: how to create subplots in for loop?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to create a subplot for every column in the dataframe but I am not able to achieve it when I tried to use the code below

fig = plt.figure()
# Extrapolate each column
for col in df.columns:
    # Get the index values for NaNsY in the column
    x = df[pd.isnull(df[col])].index.astype(float).values
    x1 = df.index.astype(float).values
    y = df[col].values
    # Extrapolate those points with the fitted function
    df[col][x] = func(x, *col_params[col])
    ax = fig.add_subplot(5,5,col)
    ax.plot(x1,y,func(x, *col_params[col]),'g--')
TypeError: '<' not supported between instances of 'str' and 'int'

how can I do this correctly? thanks
Please provide the full error traceback. I don't see a "<" in your code so the error is likely something being passed into a function.