Removing colored axis markers from Python plot

edit: to improve the example code / upload the improved image

I am using pylab to plot a graph in Python (sample code is shown below). The plot is displayed correctly, however I cannot find a way to remove the lines connecting the colored axes (shown in the graph below), which makes the graph rather unsightly.

I searched the forums and didn't find a similar question, so any help would be appreciated.

thank

Code instance used for the graph:

Code based on the example shown here: http://code.activestate.com/recipes/578256-script-that-compares-various-interest-rate-term-st/

from pylab import plot, title, xlabel, ylabel, show

r0 = 0.5 # current UK funding rate
b = 2.0 # 1 % long term interest rate
a = 0.1#speed of reversion
beta = 0.2#SD

n = 1    # number of simulation trials
T = 15.    # time of projection
m = 15.   # subintervals
dt = T/m  # difference in time each subinterval

r = np.zeros(shape=(n, m), dtype=float) # matrix to hold short rate paths


        #loop used to simulate interest rates and plot points
        for i in np.arange(1,m):                
        r[j,i] = r[j,i-1] + a*(b-r[j,i-1])*dt + beta*sqrt(dt)*standard_normal();        
        plot(np.arange(0, T, dt), r[j],linestyle='--')

show()

      

enter image description here

0


source to share


1 answer


If I understand correctly, you are just drawing all rows for index j.

What you want is perhaps just r [0 ,:] for the first simulation. If so, after the next i j for-look, do this

figure() # create a new figure canvas
plot(np.arange(0, T, dt), r[0,:], ,linestyle='--')

      

Does this help solve the problem?

(edit) Then the problem is probably that you want intermediate results. I just took the maximum intermediate result and plotted it as a thicker line.



from pylab import *


r0 = 0.5 # current UK funding rate
b = 2.0 # 1 % long term interest rate
a = 0.1#speed of reversion
beta = 0.2#SD

n = 1    # number of simulation trials
T = 15.    # time of projection
m = 15.   # subintervals
dt = T/m  # difference in time each subinterval

r = np.zeros(shape=(n, m), dtype=float) # matrix to hold short rate paths

temp = [] # to save intermediate results
j = 0
clf()
x = np.arange(0, T, dt)
#loop used to simulate interest rates and plot points
for i in np.arange(1,m):                
    r[j,i] = r[j,i-1] + a*(b-r[j,i-1])*dt + beta*sqrt(dt)*standard_normal()
    temp.append(r[j,:])   

    plot(x, r[j,:],linestyle='--')

results = np.array(temp)
plot( x, results.max(axis=0), linewidth=2 )

      

(edit2)

In fact, the end result is the same as max. So

plot(x, results[-1,:])

      

enough ...

0


source







All Articles