0

我有一个至少包含 10 个不同类别的数据集。在每个班级中,我至少有 20 个数据点。当我使用“散点图”时,我的数据集用不同的颜色绘制,以根据它们的类在数据点之间做出不同。但是,我将使用特定颜色(例如蓝色)的范围绘制我的数据集,即从深蓝色到浅蓝色。

我们如何在 MATLAB 中为绘图定义特定颜色的范围?

4

1 回答 1

0

Consider the following example:

%# some random xy points with random 1 to 10 classes
data = [rand(100,2) randi([1,10],[100 1])];

%# colormap from dark to light blue: 10-by-3 matrix
clr = linspace(0,1,10)';
clr(:,2:3) = 0;
clr = fliplr(clr);

%# scatter plot
scatter(data(:,1), data(:,2), 10, clr(data(:,3),:))
colormap(clr), colorbar    %# fake color legend

plot

So label=1 is mapped to [0,0,0] (dark blue or just black) up to label=10 which is mapped to [0,0,1] (full blue color)


Ok my colormap is not the best, perhaps you should use one of the builtin ones. For example, replace it with:

clr = winter(10);    %# or: cool(10)

in the above code

于 2013-04-26T16:47:17.647 回答