Change color of 2D plot line depending on 3rd value

前端 未结 5 1978
Happy的楠姐
Happy的楠姐 2020-11-30 10:40

I have a data set that looks like this

 140400 70.7850 1
 140401 70.7923 2
 140402 70.7993 3
 140403 70.8067 4
 140404 70.8139 5
 140405 70.8212 3

5条回答
  •  死守一世寂寞
    2020-11-30 11:02

    Do you have Matlab R2014b or higher?

    Then you could use some undocumented features introduced by Yair Altman:

    n = 100;
    x = linspace(-10,10,n); y = x.^2;
    p = plot(x,y,'r', 'LineWidth',5);
    
    %// modified jet-colormap
    cd = [uint8(jet(n)*255) uint8(ones(n,1))].' %'
    
    drawnow
    set(p.Edge, 'ColorBinding','interpolated', 'ColorData',cd)
    

提交回复
热议问题