从Python图中删除彩色轴标记

时间:2015-04-25 10:46:55

标签: python numpy matplotlib plot

编辑:增强代码示例/上传改进的图片

我使用pylab在Python中绘制图形(示例代码如下所示)。该图显示正确,但是,我找不到删除彩色轴连接线的方法(如下图所示),这使得图形相当难看。

我搜索过论坛并没有找到类似的问题,所以任何帮助都会受到赞赏。

谢谢

用于剧情的代码提取:

基于此处给出的示例的代码: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

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你只是绘制j索引的所有行。

你想要的可能只是第一次模拟的r [0,:]。如果是这样,在下一个i j for-look之后,执行此操作

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

这是否解决了这个问题?

(编辑) 然后,可能问题是你需要的是中间结果。我只取了中间结果的最大值并将其绘制为粗线。

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)

实际上,最终结果与max相同。所以

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

就够了......