在Matlab中更改颜色图的最简单方法是用多条线绘制



让我们以我为模拟算术布朗运动而写的这段代码为例:

%% Simulate an arithmetic Brownian motion
% $$ dX(t) = mu*dt + sigma*dW(t) $$
% Define parameters and time grid
npaths = 500; % number of paths (trajectories)
T = 1; % time horizon
nsteps = 150; % number of time steps
dt = T/nsteps; % time step size
t = 0:dt:T; % observation times
mu = 0.2; sigma = 0.3; % model parameters
% Compute the increments 
dX = mu*dt + sigma*sqrt(dt)*randn(nsteps,npaths);
% Accumulate the increments: compute the ABM
X = [zeros(1,npaths); cumsum(dX)]; % sets first row as zero
% Plot 20 sample trajectories
figure(1);
plot(t,X(:,1:20)); % just select 20 trajectory for clarity's sake

在这里我画了20条轨迹,但我想找到一种方法来改变我选择的任何数量轨迹的颜色图。我想要更明亮的颜色。每次我绘制任何随机过程模拟时,我都会遇到这个问题,所以我正在寻找一些我每次都可以使用的通用的、可能简单的东西。有人知道怎么做吗?

我使用了@mikkola建议,函数distinguishable_colors

% Plot 20 sample trajectories
c = distinguishable_colors(20);
a = axes; hold(a,'on');
set(a,'ColorOrder',c);  
%  
plot(t,X(:,1:20));   

当然,它也适用于不同数量的轨迹。

最新更新