Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7420855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:18:41+00:00 2026-05-29T08:18:41+00:00

I have a code in which for 3 different values of D ,i have

  • 0

I have a code in which for 3 different values of D ,i have 3 different values of dx and so,3 different plots.

I want to do a plot which will have all 3 plots in one.

...
D=(0.133e-4,0.243e-4,0.283e-4)

dx=sc.zeros(3)
    for i in D:
        dx[i]=sc.sqrt(D[i]*dt/M)

        plt.ion()
        while n<N:
            Vw_n=Vw_n1
            C_n=C_n1
            R2=(Vw_n+B1)/(Vw_0+B1)
            Cc=C_n1[0]/C0
            F2_1=10000/3*Pw*A*(C0*Vw_0/Vw_n1-C_n[1])
            dV=F2_1*dt
            Vw_n1=Vw_n+dV
            C_n1[0]=C0*Vw_0/Vw_n1
            F_i_2=-D[i]/dx[i]*(C_n[1:7]-C_n[0:6])
            C_n1[0:6]=C_n[0:6]-F_i_2*A*dt/(L/(V0/A)*V0/5)
            n+=1
            ttime=n*0.02*1000

            #-----PLOT AREA---------------------------------#

            mylabels=('T=273','T=293','T=298')
            colors=('-b','or','+k')

            if x==1:
                plt.plot(ttime,R2,mylabels[i],colors[i])
            elif x==2:
                plt.plot(ttime,Cc,mylabels[i],colors[i])
            plt.draw()
            plt.show()

———-RUNNABLE————————–

import scipy as sc
import matplotlib.pyplot as plt


def graph(x):

    A=1.67e-6  
    V0=88e-12 
    Vw_n1=71.7/100*V0 
    Pw=0.22   
    L=4e-4
    B1=V0-Vw_n1   

    C7=0.447e-3  



    dt=0.2e-4
    M=0.759e-1

    C_n1=sc.zeros(7)
    C_n1[0:6]=0.290e-3
    C_n1[6]=0.447e-3


    C0=C_n1[0]
    Vw_0=Vw_n1

    N=2000 
    n =1
    D = ,0.243e-4
    dx = sc.sqrt(D*dt/M)

        plt.ion()
        while n<N:
            Vw_n=Vw_n1
            C_n=C_n1
            R2=(Vw_n+B1)/(Vw_0+B1)
            Cc=C_n1[0]/C0
            F2_1=10000/3*Pw*A*(C0*Vw_0/Vw_n1-C_n[1])
            dV=F2_1*dt
            Vw_n1=Vw_n+dV
            C_n1[0]=C0*Vw_0/Vw_n1
            F_i_2=-D/dx*(C_n[1:7]-C_n[0:6])
            C_n1[0:6]=C_n[0:6]-F_i_2*A*dt/(L/(V0/A)*V0/5)
            n+=1
            ttime=n*0.02*1000

            #-----PLOT AREA---------------------------------#


            if x==1:
                plt.plot(ttime,R2)
            elif x==2:
                plt.plot(ttime,Cc)
            plt.draw()
            plt.show()

My problem is that i want to plot (ttime,R2) and (ttime,Cc).
But i can’t figure how to call R2 and Cc for the 3 different values of D (and dx).

Also, i am taking an error: tuple indices must be integers, not float

at dx[i]=sc.sqrt(D[i]*dt/M).

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:18:42+00:00Added an answer on May 29, 2026 at 8:18 am

    Consider these lines:

    D=(0.133e-4,0.243e-4,0.283e-4)
    for i in D:
        dx[i]=sc.sqrt(D[i]*dt/M)
    

    i is a float. It can not be used as an index into the tuple D.
    (D[i] does not make sense.)

    Perhaps you meant

    D=(0.133e-4,0.243e-4,0.283e-4)
    for i, dval in enumerate(D):
        dx[i] = sc.sqrt(dval*dt/M)
    

    Or, simply

    import scipy as sc
    D = sc.array([0.133e-4,0.243e-4,0.283e-4])
    dx = sc.sqrt(D*dt/M)
    

    • Don’t call plt.plot once for each point. That road leads to
      sluggish behavior. Instead, accumulate an entire curve’s worth of
      data points, and then call plt.plot once for the entire curve.
    • To plot 3 curves on the same figure, simply call plt.plot 3 times.
      Do that first before calling plt.show().
    • The while not flag loop was not ending when you enter 1 for x,
      because if x==2 should have been elif x==2.
    • To animate a matplotlib plot, you should still try to avoid multiple
      calls to plt.plot. Instead, use plt.plot once to make a Line2D
      object, and then update the underlying data with calls to
      line.set_xdata and line.set_ydata. See Joe Kington’s example and this example from the matplotlib docs.

    import scipy as sc
    import matplotlib.pyplot as plt
    
    def graph(x):
        plt.ion()
        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)
        lines = []
        D = (0.133e-4, 0.243e-4, 0.283e-4)
        temperatures = ('T = 273','T = 293','T = 298')
        N = 2000
        linestyles = ('ob', '-r', '+m')
        for dval, linestyle, temp in zip(D, linestyles, temperatures):
            line, = ax.plot([], [], linestyle, label = temp) 
            lines.append(line)
        plt.xlim((0, N*0.02*1000))        
        if x == 1:
            plt.ylim((0.7, 1.0))
        else:
            plt.ylim((1.0, 1.6))
        plt.legend(loc = 'best')        
        for dval, line in zip(D, lines):
            A = 1.67e-6
            V0 = 88e-12
            Vw_n1 = 71.7/100*V0
            Pw = 0.22
            L = 4e-4
            B1 = V0-Vw_n1
            C7 = 0.447e-3
            dt = 0.2e-4
            M = 0.759e-1
            C_n1 = sc.zeros(7)
            C_n1[0:6] = 0.290e-3
            C_n1[6] = 0.447e-3
            C0 = C_n1[0]
            Vw_0 = Vw_n1
    
            tvals = []
            yvals = []
            dx = sc.sqrt(dval*dt/M)
            for n in range(1, N+1, 1):
                Vw_n = Vw_n1
                C_n = C_n1
                R2 = (Vw_n+B1)/(Vw_0+B1)
                Cc = C_n1[0]/C0
                F2_1 = 10000/3*Pw*A*(C0*Vw_0/Vw_n1-C_n[1])
                dV = F2_1*dt
                Vw_n1 = Vw_n+dV
                C_n1[0] = C0*Vw_0/Vw_n1
                F_i_2 = -dval/dx*(C_n[1:7]-C_n[0:6])
                C_n1[0:6] = C_n[0:6]-F_i_2*A*dt/(L/(V0/A)*V0/5)
                tvals.append(n*0.02*1000)
                yvals.append(R2 if x == 1 else Cc)
                if not len(yvals) % 50:
                    line.set_xdata(tvals)
                    line.set_ydata(yvals)
                    fig.canvas.draw()
    
    if __name__ == "__main__":
        flag = False
        while not flag:
            try:
                x = int(raw_input("Give a choice 1  or 2  : "))
                flag = True
                if x == 1:
                    plt.title('Change in cell volume ratio as a function of time \n\
                    at various temperatures')
                    plt.xlabel('Time')
                    plt.ylabel('Ceil volume ratio (V/V0)')
                    graph(x)
                elif x == 2:
                    plt.title('Increase of solute concentration at various temperatures')
                    plt.xlabel('Time')
                    plt.ylabel('Solute concentration in the Ceil (Cc)')
                    graph(x)
                else:
                    flag = False
                    print("You must input 1 or 2")
            except ValueError:
                print("You must input 1 or 2")
        raw_input('Press a key when done')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 queries which display 2 different values but the results from one
I have some conditional calls from my code which starts same service with different
Here I have one file which contains some information, and I want to check
I have code which needs to do something like this There is a list
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have code which as been working against an older Active Directory server and
I already have code which lazy loads scripts on request. My issue now is
I have some code which collects points (consed integers) from a loop which looks
I have have some code which adds new cells to a table and fills
I have some code which utilizes parameterized queries to prevent against injection, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.