【问题标题】:Set colorbar ranges in 3d graph in matlab在matlab的3d图中设置颜色条范围
【发布时间】:2012-09-28 04:19:32
【问题描述】:

我想用这个创建一个三维表面:

>> a=X

a =

Columns 1 through 8

           0          50         100         150         200         250         300         350

Columns 9 through 16

         400         450         500         550         600         650         700         750

Columns 17 through 21

         800         850         900         950        1000

>> b=Y

b =

     0
    50
   100
   150
   200
   250
   300
   350
   400

>> c=Z

c =
Columns 1 through 8

           0           0           0           0           0           0           0           0
          16          32          67          98         127         164         194         234
         120         171         388         773        1086        1216        1770        2206
         189         270         494        1978        2755        3134        5060       10469
         133         166         183         348         647         937        1446        2304
         192         162         154         113         161         189         266         482
           0           0           0           0           0           0           0           0
           0           0           0           0           0           0           0           0
           0           0           0           0           0           0           0           0

Columns 9 through 16

           0           0           0           0           0           0           0           0
         366         604         529         504         346         226         228         179
        4027       11186       10276        5349        2560        1322         996         799
       27413       76387       37949       15591        5804        2654        1803        1069
        9844       24152       14772        4613        1777         849         459         290
        1288        2623        1538         582         280         148          90          56
           0           0           0           0           0           0           0           0
           0           0           0           0           0           0           0           0
           0           0           0           0           0           0           0           0

Columns 17 through 21

           0           0           0           0           0
         108          94          79           0           0
         646         476         612           0           0
         884         858         722           0           0
         266         215         139           0           0
          48          48          31           0           0
           0           0           0           0           0
           0           0           0           0           0
           0           0           0           0           0



>> surf(X,Y,Z)

同时我想定义 Z 值 = 2755 绿色。颜色条的限制可以是 Z 的最小值和最大值(从 0 到 76387)。如何设置颜色条的范围以获得此结果?

【问题讨论】:

    标签: matlab plot surf colorbar


    【解决方案1】:

    这将按照您的要求进行:

    %# add red (row 1), yellow (row 2), green (row 2)
    map = [1 0 0; 0 1 1; 0 1 0];  
    
    %# set the new map as the current map
    colormap(map); 
    
    colors = zeros(size(c));          %# create colors array          
    colors(c <= 1803) = 1;            %# red (1)
    colors(c > 1803 & c < 2755) = 2;  %# yellow (2)
    colors(c >= 2755) = 3;            %# green (3)
    
    %# and pass it into surf     
    surf(a,b,c, colors) 
    

    【讨论】:

      猜你喜欢
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多