【问题标题】:Color points on a plot according to a vector in Octave根据 Octave 中的向量在绘图上着色点
【发布时间】:2015-05-21 10:01:08
【问题描述】:

我想绘制存储在 N-by-3 矩阵中的多个 2d 点。前 2 列定义 x 和 y 坐标。第 3 列定义用于单个点的颜色索引,并引用如下颜色代码列表:

c={[1 0 0], [0 1 0], [0 0 1]}

然后我调用 plot 函数:

plot(points(:,1), points(:,2), '.', 'Color', c(points(:,3)));

但我只得到错误:

颜色属性“color”的值无效

有没有办法用每个点的相应颜色来绘制点?

【问题讨论】:

    标签: matlab plot octave


    【解决方案1】:

    使用scatter 代替绘图:

    %// Making dummy data:
    n = 10;
    points = rand(n,2);
    points(:,3) = randi(3,n,1);
    
    %//Setting a colormap: note that you should not use a cell array for this!
    c=[1 0 0; 0 1 0; 0 0 1]
    colormap(c)
    
    %//plot
    scatter(points(:,1), points(:,2), [], points(:,3))
    

    【讨论】:

      猜你喜欢
      • 2020-07-07
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 2012-05-08
      • 2018-09-22
      • 1970-01-01
      相关资源
      最近更新 更多