【问题标题】:Matlab - plot and color samples based on dataMatlab - 基于数据的绘图和颜色样本
【发布时间】:2016-09-03 19:52:34
【问题描述】:

我有以下数据:

  • dataMatrix (20x210):20 个样本,每个样本 210 个变量
  • 波长:1 行,共 210 个变量,描述波长数
  • 浓度:每个样品的浓度值(20 行 1 列)

我通常以正常的方式绘制数据:

plot(wavelength, dataMatrix)

但我想要的是根据浓度值绘制和着色每个样本,同时考虑到其余部分,根据数据着色。我认为这与颜色图有关。结果会是这样的:

有没有什么简单的方法可以用 Matlab 做到这一点?

非常感谢!

【问题讨论】:

标签: matlab matrix plot colormap


【解决方案1】:

plot 接受包含线条颜色的线条属性,例如

plot(wavelength, dataMatrix, 'Color', [0,0,0.1])

colormap 可以将内置颜色图转换为 RGB 矩阵,如

nlines = length(concentrations);
cmap = hsv(nlines)

将浓度映射到颜色就像对数字进行排序一样简单

c = concentrations - min(concentrations);
c = ceil( c/max(c)*nlines );

最后,分别画出每一行

for ii = 1:nlines
    plot(wavelength, dataMatrix(ii,:), 'Color', cmap(c(ii),:))
    hold on
end
hold off

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 2014-10-30
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    相关资源
    最近更新 更多