0

I am trying to plot multiple graphs in one diagram. I am planning to do it with a for loop.

x = df1['mrwSmpVWi']
c = df['c']
a = df['a']
b = df['b']
    
y = (c / (1 + (a) * np.exp(-b*(x))))
   
for number in df.Seriennummer:
    plt.plot(x,y, linewidth = 4)
    plt.title("TEST")
    plt.xlabel('Wind in m/s')
    plt.ylabel('Leistung in kWh')
    plt.xlim(0,25)
    plt.ylim(0,1900)
    plt.show()

The calculation doesn't work I just get dots in the diagram and I get 3 different diagrams.

This is the df:

Seriennummer    c   a   b
0   701085  1526    256 0.597
1   701086  1193    271 0.659
2   701087  1266    217 0.607

Does someone know what I did wrong? [![enter image description here][1]][1]

Df1 has about 500,000 rows. This is a part of df1:

    Seriennummer    mrwSmpVWi   mrwSmpP
422 701087.0    2.9 25.0
423 701090.0    3.9 56.0
424 701088.0    3.2 22.0
425 701086.0    4.0 49.0
426 701092.0    3.7 46.0
427 701089.0    3.3 0.0
428 701085.0    2.4 4.0
429 701091.0    3.6 40.0
430 701087.0    2.7 11.0
431 701090.0    3.1 23.0
432 701086.0    3.6 35.0

The expected output schould be a diagram with multiple logitic graphs. Something like that: [![enter image description here][2]][2]

EDIT:

1lk4
  • 43
  • 6

1 Answers1

1

I guess you are using matplotlib. You can use something like

import matplotlib.pyplot as plt

# some calculations for x and y ...

fig, ax = plt.subplots(ncols=1,nrows=1)

for i in range(10):
    ax.plot(x[i],y[i])

plt.show()

Further information can be found on the matplotlib subplots documentation> https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots.html

Because you problem is related to the pandas data frames, try something like

for number in df.Seriennummer:
    x = df1.loc['Seriennummer'==number]['mrwSmpVWi']
    y = (c['Seriennummer'==number] / (1 + (a['Seriennummer'==number]) * np.exp(-b['Seriennummer'==number]*(x))))
    plt.plot(x,y, linewidth = 4)
A. Baur
  • 602
  • 5
  • 7
  • Thank you for the answer: I still just get an empty diagramm. Don't I need to define i somewhere? What should be my i? – 1lk4 Sep 22 '20 at 12:02
  • Sorry, your title is a bit confusing, I didn't addressed the problem right in the first time. I guess your problem is related to your pandas dataframes. The way how you select your x value... is it possible that you just select a single value. And also you just calculate a singele value y. Thats why you just get a single dot for each loop. – A. Baur Sep 22 '20 at 12:13
  • Ah ok. I will try to chage it a little. thank you :) – 1lk4 Sep 22 '20 at 12:20
  • if still problems occur because you cant extract the specific value from the cell, have a look to: https://stackoverflow.com/questions/16729574/how-to-get-a-value-from-a-cell-of-a-dataframe – A. Baur Sep 22 '20 at 12:22
  • Hey, I tried it with fixed values for my c,a,b. But if I draw the graph it looks like it is just one and it always starts new from the beginning becuase there are straight lines in my diagram. I added an picture to the question – 1lk4 Sep 22 '20 at 12:36
  • ahh, yes, I think you have to select the x values also to the serial number within the for loop? x = df1.loc['Seriennummer'==number]['mrwSmpVWi'] – A. Baur Sep 22 '20 at 13:44