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 8973191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:23:26+00:00 2026-06-15T18:23:26+00:00

# Import plotting routines from pylab import * # 1D ODE that has a

  • 0
# Import plotting routines
from pylab import *

# 1D ODE that has a pitchfork bifurcation
# x_dot = r * x - x * x * x
def PitchforkODE(r,x):
return r * x - x * x * x

# 1D Euler
def OneDEuler(r,x,f,dt):
    return x + dt * f(r,x)

# Improved 1D Euler
def ImprovedOneDEuler(r,x,f,dt):
xtemp = x + dt * f(r,x)
return x + dt * ( f(r,x) + f(r,xtemp) ) / 2.0

# 4th Order Runge-Kutta Euler Method
def RKOneD(r,x,f,dt):
k1 = dt * f(r,x)
k2 = dt * f(r,x + k1/2.0)
k3 = dt * f(r,x + k2/2.0)
k4 = dt * f(r,x + k3)
return x + ( k1 + 2.0 * k2 + 2.0 * k3 + k4 ) / 6.0

# Integrator function that calls one of the three functions
# Fills up array
def Integrator(x1,x2,x3,x4,t,N,Func,dt):
    for n in xrange(0,N):
        x1.append( Func(r,x1[n],PitchforkODE,dt) )
        x2.append( Func(r,x2[n],PitchforkODE,dt) )
        x3.append( Func(r,x3[n],PitchforkODE,dt) )
        x4.append( Func(r,x4[n],PitchforkODE,dt) )
        t.append( t[n] + dt )

# Simulation parameters
# Integration time step
dt = 0.2


# Control parameter of the pitchfork ODE:
r = 1.0

# Set up arrays of iterates for four different initital conditions
x1 = [ 0.1]
x2 = [-0.1]
x3 = [ 2.1]
x4 = [-2.1]
x5 = [ 0.1]
x6 = [-0.1]
x7 = [ 2.1]
x8 = [-2.1]
x9 = [ 0.1]
x10 = [-0.1]
x11 = [ 2.1]
x12 = [-2.1]

# Time
t  = [ 0.0]

# The number of time steps to integrate over
N = 50

#The different functions
a = OneDEuler
b = ImprovedOneDEuler
c = RKOneD

# Setup the plot
subplot(3,1,1)
Func = a
Integrator(x1,x2,x3,x4,t,N,Func,dt)
ylabel('x(t)') # set y-axis label
title(str(Func.func_name) + ': Pitchfork ODE at r= ' + str(r)) # set plot title
axis([0.0,dt*(N+1),-2.0,2.0])
# Plot the time series
plot(t,x1,'b')
plot(t,x2,'r')
plot(t,x3,'g')
plot(t,x4,'m')

subplot(212)
Func = b
Integrator(x5,x6,x7,x8,t,N,Func,dt)
ylabel('x(t)') # set y-axis label
title(str(Func.func_name) + ': Pitchfork ODE at r= ' + str(r)) # set plot title
axis([0.0,dt*(N+1),-2.0,2.0])
# Plot the time series
plot(t,x5,'b')
plot(t,x6,'r')
plot(t,x7,'g')
plot(t,x8,'m')

subplot(3,1,3)
Func = c
Integrator(x9,x10,x11,x12,t,N,Func,dt)
xlabel('Time t') # set x-axis label
ylabel('x(t)') # set y-axis label
title(str(Func.func_name) + ': Pitchfork ODE at r= ' + str(r)) # set plot title
axis([0.0,dt*(N+1),-2.0,2.0])
# Plot the time series
plot(t,x9,'b')
plot(t,x10,'r')
plot(t,x11,'g')
plot(t,x12,'m')  

I’m trying to plot 3 different subplots on the same display window. One on top of the other. So basically, 3 rows 1 column. Each plot represents a different function a, b or c. Each plot should have 4 different lines.

  • 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-06-15T18:23:27+00:00Added an answer on June 15, 2026 at 6:23 pm

    Well…It looks like you are doing the plotting part correctly. The code below gives you the figure further below.

    from pylab import *
    subplot(3,1,1)
    plot(arange(33))
    subplot(3,1,2)
    plot(arange(44))
    subplot(3,1,3)
    plot(arange(55),'r')
    

    enter image description here

    Your code does have some problems though, the first thing I found was that your t and x vectors aren’t the same size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Module OneDMaps: def LogisticMap(a,nIts,x): for n in xrange(0,nIts): return 4.*a*x*(1.-x) Actual Program: # Import
Suppose you have a 2D curve, given by e.g.: from matplotlib import pylab t
import MySQLdb import sys from libdesklets.controls import Control from IDBConnection import IDBConnection class DBConnection(Control,
import httplib2 from urllib import urlencode h = httplib2.Http() h.add_credentials('zackster@gmail.com', 'PassWord') data = dict(key=ThisIsMyApiKeyICopiedAndPastedIt)
I am plotting a confusion matrix with matplotlib with the following code: from numpy
I am trying to adapt the underlying structure of plotting code (matplotlib) that is
I am plotting data on a map using this code: import numpy as np
I have a 2D array that I'm plotting with imshow and I would like
import sys def keepsumming(number): numberlist = [] for digit in str(number): numberlist.append(int(digit)) total =
import wx import wx.grid as gridlib ######################################################################## class PanelOne(wx.Panel): #---------------------------------------------------------------------- def __init__(self, parent): Constructor

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.