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
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,681 Nov-07-2023, 09:49 AM
Last Post: buran
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,656 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,703 Aug-19-2022, 11:07 AM
Last Post: dm222
Question Error with MatPlotLib subplots Danno 8 3,404 Apr-01-2022, 12:23 AM
Last Post: Danno
  Create Dynamic For Loop quest 3 4,376 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 8,852 Feb-28-2021, 06:20 PM
Last Post: Larz60+
  how to create pythonic codes including for loop and if statement? aupres 1 1,919 Jan-02-2021, 06:10 AM
Last Post: Gribouillis
  create loop of subplot plotly dash without hardcode tonycat 0 3,904 Sep-23-2020, 08:40 AM
Last Post: tonycat
  Create tempfile that use in loop for insert into DB Firsttimepython 2 2,126 May-29-2020, 04:15 PM
Last Post: Firsttimepython
  Create, assign and print variables in loop steven_tr 10 4,331 May-28-2020, 04:26 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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