【问题标题】:What is the easiest way to change the colormap in Matlab plots with many lines用多条线更改 Matlab 图中颜色图的最简单方法是什么
【发布时间】:2015-12-15 11:07:50
【问题描述】:

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

%% 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 条轨迹,但我想找到一种方法来更改我选择的任意数量的轨迹的颜色图。我想要更鲜艳的颜色。每次我绘制任何随机过程模拟时都会遇到这个问题,所以我正在寻找我每次都可以使用并且可能很简单的通用方法。有谁知道该怎么做?

【问题讨论】:

标签: matlab plot colors


【解决方案1】:

我使用了@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));   

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-21
    • 2014-03-09
    • 2018-03-13
    • 2018-08-16
    • 1970-01-01
    • 2010-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多