【问题标题】:Plot multiple columns with different colors in MATLAB在 MATLAB 中绘制具有不同颜色的多列
【发布时间】:2017-11-07 22:03:52
【问题描述】:

我有一个 372x15 的矩阵。我试图以这样的方式绘制它,即第 1-14 列将位于 x 轴上,每列具有不同的颜色,而第 15 列将被视为 y 轴。例如,带有跟随 (x1, y)、(x2, y) 依此类推的图,其中 x1 是第 1 列中的所有数据点。这是一个简单的散点图。我怎样才能在 MATLAB 上做到这一点?

【问题讨论】:

  • “第 15 列将在 y 轴上”是什么意思?
  • 说的有点清楚了,但是第15列的数据和对应的其他列会被绘制出来。

标签: matlab graph scatter-plot


【解决方案1】:

一个简单的方法就是使用plot(A(:,1:end-1), A(:,end), '.')。这是一个例子:

A = [(1:14)-.6*rand(372,14) ((1:372).'+rand(372,1))]; % example A. Uses implicit expansion
plot(A(:,1:end-1), A(:,end), '.') % do the plot
axis tight % optionally make axis limits tight

以上循环通过the 7 predefined colors。如果您喜欢自定义颜色,请在调用plot 之前设置坐标区的'ColorOrder' 属性,并使用hold on 防止Matlab 重置它:

clf % clear figure
cmap = autumn(size(A,2)); % example colormap
set(gca, 'ColorOrder', cmap); % set that colormap
hold on % needed so that the colormap is not automatically reset
plot(A(:,1:end-1), A(:,end), '.')
axis tight

您可以指定不同的标记或标记大小;见plot's documentation

【讨论】:

  • 这里的想法是正确的,尽管我解释说 OP 希望垂直的 y 轴值由最后一列确定,而不是水平的 x 轴。调用plot 时可能会通过交换参数顺序来更改。
猜你喜欢
  • 2011-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-06
  • 1970-01-01
  • 1970-01-01
  • 2019-10-09
  • 1970-01-01
相关资源
最近更新 更多