Python Forum
how to create subplots in for loop?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to create subplots in for loop?
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  in c# create a loop counting from 0 to 5, consecutively Frankd 19 2,216 Apr-01-2025, 12:46 PM
Last Post: Frankd
  How to create a variable only for use inside the scope of a while loop? Radical 10 8,229 Nov-07-2023, 09:49 AM
Last Post: buran
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 2,791 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 2,935 Aug-19-2022, 11:07 AM
Last Post: dm222
Question Error with MatPlotLib subplots Danno 8 5,912 Apr-01-2022, 12:23 AM
Last Post: Danno
  Create Dynamic For Loop quest 3 6,074 Apr-26-2021, 02:03 PM
Last Post: ibreeden
  Python Matplotlib: How do I save (in pdf) all the graphs I create in a loop? JaneTan 1 11,179 Feb-28-2021, 06:20 PM
Last Post: Larz60+
  how to create pythonic codes including for loop and if statement? aupres 1 2,418 Jan-02-2021, 06:10 AM
Last Post: Gribouillis
  create loop of subplot plotly dash without hardcode tonycat 0 4,590 Sep-23-2020, 08:40 AM
Last Post: tonycat
  Create tempfile that use in loop for insert into DB Firsttimepython 2 3,040 May-29-2020, 04:15 PM
Last Post: Firsttimepython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020