Reputation: 397
I have a dataset with at least 10 different classes. In each class, i have at least 20 data points. When i use 'scatter plot', my dataset plots with different colors to make different between data points based on their classes. But, I am going to plot my dataset with range of a specific color such as blue, i.e., from dark blue to light blue.
How we can define a range of a specific color for a plot in MATLAB?
Upvotes: 0
Views: 1466
Reputation: 124563
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
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
Upvotes: 0