从 Python 图中删除彩色轴标记 [英] Removing coloured axis markers from Python plot

查看:39
本文介绍了从 Python 图中删除彩色轴标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

edit: to enhance code example/upload improved picture

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

I am using pylab to plot a graph in Python (example code shown below). The plot appears correctly, however, I can not find a way of removing the coloured axis join lines (shown on the graph below), which make the graph fairly unsightly.

我已经搜索了论坛,但没有找到类似的问题,因此我们将不胜感激.

I have searched the forums and not found a similar question, so any help would be appreciated.

谢谢

用于绘图的代码摘录:

基于此处给出的示例的代码:

Code based on example given 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()

推荐答案

如果我理解正确,那么您只是在绘制j索引的所有行.

If I understand correctly, you are just plotting all the lines for j index.

对于第一次模拟,您想要的可能只是r [0 ,:].如果是这样,请在下一次查看之后,执行此操作

What you want is probably 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='--')

这可以解决问题吗?

(编辑)然后,可能的问题是您需要的是中间结果.我只是简单地取中间结果的最大值并将其绘制为较粗的线.

(edit) Then, probably the problem is that what you need is in the intermediate results. I took simply the max of intermediate result and plotted it as 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)

实际上,只是最终结果与max相同.所以

actually, just the final result is the same thing as max. so

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

够了...

这篇关于从 Python 图中删除彩色轴标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆