【问题标题】:I have a 2D plot in Matlab where I want to specify the RGB value for each point to vary to color我在 Matlab 中有一个 2D 图,我想为每个点指定 RGB 值以改变颜色
【发布时间】:2014-11-14 23:27:54
【问题描述】:

我正在尝试在 Matlab 中绘制一条 2D 线,其颜色根据我分配给每个点的 RGB 代码而变化。下面的代码适用于给定的颜色图(定义颜色的“col”值),但我试图更严格地控​​制颜色分配,以便值始终在多个图表中呈现相同的颜色。

surface([x;x],[y;y],[z;z],[col;col],...
    'facecol','no',...
    'edgecol','interp',...
    'linew',2);

【问题讨论】:

  • 你能发布你的完整代码吗?我们无法最终重建问题。
  • 对每个段使用一次line 调用,并使用语法line(..., 'Color', [r g b]) 指定确切的颜色

标签: matlab graph colors 2d


【解决方案1】:

问题是你如何决定每个点的颜色?定义颜色图很容易(如下所示)。

col=colormap(hot(128)) %% or other colour style like hsv or jet

如果你有一个变量(我们称之为 V),它的每个点都有一个特定的值,并且你希望颜色根据它来改变:

首先定义颜色图中的极值:

min_col=0; %%%can be the minimum of V
max_col=1; %%%can be the maximum of V

然后插入到您的数据中

new_col=interp1(linspace(min_col,max_col,length(col)),col, V(:))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 2012-04-03
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多