0
votes

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?

1
how are you producing the 'scatter plot', gscatter? - Amro
scatter(data(:,1), data(:,2), 10, data(:,3)); - BlueBit
can you share your code and data? I'm thinking you can build your own colormap using linear interpolation... - Amro
my coding is very simple. First, i have called my data from a .mat file. This file includes a matrix in 1000*3. last (3rd) column is a label from 1 to 10 to classify data points in 10 different class. 1st and 2nd columns are (x,y) points. Then, i have used scatter(data(:,1), data(:,2), 10, data(:,3)) to plot my data. but i need show a range of color from dark blue to light blue instead of 10 different colors. - BlueBit

1 Answers

0
votes

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