Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Color / 3D plots

Subject: Color / 3D plots

From: Paul

Date: 21 Jun, 2011 21:11:02

Message: 1 of 9

Hello,
This should be farily easy...
I have a 1000x3 matrix. I am looking to do a color plot, where column #1 defines the x axis, column #2 defines the y axis, and column #3 is the color.

I would also be interested in knowing how to do a 3D plot with the same matrix.

I haven't quite been able to figure out the proper command/syntax.

Thanks!

Subject: Color / 3D plots

From: Sadik

Date: 21 Jun, 2011 21:23:05

Message: 2 of 9

Hi Paul,

For the 3D plot, you can use plot3.

plot3(M(:,1),M(:,2),M(:,3),'*')

What do you mean by color plot?

Best.

Subject: Color / 3D plots

From: Jeff

Date: 21 Jun, 2011 21:35:20

Message: 3 of 9

"Paul " <palex71@hotmail.com> wrote in message <itr1d6$k7h$1@newscl01ah.mathworks.com>...
> Hello,
> This should be farily easy...
> I have a 1000x3 matrix. I am looking to do a color plot, where column #1 defines the x axis, column #2 defines the y axis, and column #3 is the color.
>
> I would also be interested in knowing how to do a 3D plot with the same matrix.
>
> I haven't quite been able to figure out the proper command/syntax.
>
> Thanks!

Can you give an example of your data, and a bit more description on what you want your plot to look like? Specifically, how are you representing color in a single column.

Subject: Color / 3D plots

From: Paul

Date: 21 Jun, 2011 22:10:20

Message: 4 of 9

"Jeff " <jea@gene.dot.com> wrote in message <itr2qo$o1r$1@newscl01ah.mathworks.com>...
> "Paul " <palex71@hotmail.com> wrote in message <itr1d6$k7h$1@newscl01ah.mathworks.com>...
> > Hello,
> > This should be farily easy...
> > I have a 1000x3 matrix. I am looking to do a color plot, where column #1 defines the x axis, column #2 defines the y axis, and column #3 is the color.
> >
> > I would also be interested in knowing how to do a 3D plot with the same matrix.
> >
> > I haven't quite been able to figure out the proper command/syntax.
> >
> > Thanks!
>
> Can you give an example of your data, and a bit more description on what you want your plot to look like? Specifically, how are you representing color in a single column.

For the color plot, I was looking for:
Column 1 - x axis
Column 2 - y axis
Column 3 - color point (higher value = darker color)

Good point... How would I do a plot3 with an increasing color variation with depth?

Thanks so much!

Subject: Color / 3D plots

From: Sadik

Date: 21 Jun, 2011 22:34:05

Message: 5 of 9

I had a code to do something similar. With some modification, it looks like the following. You may need to tailor it a bit for your needs.

By the way, from now on, your Column_i is Ci. :D

% Sort your values.
[sortedC3,sortingIndices] = sort(C3);
% Get the list of unique values so that each unique value will be assigned a different color.
uniqueValues = unique(sortedC3);

% Prepare your palette. The number of colors should be equal to the number of unique values. jet produces a colormap. You may want to see the documentation.
colors = jet(length(uniqueValues));

% If you think that the colors look weird, you may uncomment the following line and
% try powers other than 4 as well.
% colors = colors.^4;

% Sort the two other columns so that we don't lose track.
C1 = C1(sortingIndices);
C2 = C2(sortingIndices);

% We will go through the sorted value of C3. So, in case we get the same value, we just keep track of the previuos value and do not change the color until we get to the next distinct value. The following two variables are used for this purpose.
previousValue = uniqueValues(1);
uniqueValueCounter = 1;

% Open up a new figure window
figure;

for n = 1:length(C3)
        plot3(C1(n),C2(n),sortedC3(n),'.','Color',colors(uniqueValueCounter,:));
    
        hold on
    
        if sortedC3(n)~=previousValue
            uniqueValueCounter = uniqueValueCounter + 1;
            previousValue = uniqueValues(uniqueValueCounter);
        end
end

% Add a colormap
colormap(colors);


% Label the axes
xlabel('x')
ylabel('y')
zlabel('z')

Subject: Color / 3D plots

From: Steven_Lord

Date: 22 Jun, 2011 03:40:50

Message: 6 of 9



"Paul " <palex71@hotmail.com> wrote in message
news:itr4sc$i$1@newscl01ah.mathworks.com...
> "Jeff " <jea@gene.dot.com> wrote in message
> <itr2qo$o1r$1@newscl01ah.mathworks.com>...
>> "Paul " <palex71@hotmail.com> wrote in message
>> <itr1d6$k7h$1@newscl01ah.mathworks.com>...
>> > Hello,
>> > This should be farily easy...
>> > I have a 1000x3 matrix. I am looking to do a color plot, where column
>> > #1 defines the x axis, column #2 defines the y axis, and column #3 is
>> > the color.
>> >
>> > I would also be interested in knowing how to do a 3D plot with the same
>> > matrix.
>> >
>> > I haven't quite been able to figure out the proper command/syntax.
>> >
>> > Thanks!
>>
>> Can you give an example of your data, and a bit more description on what
>> you want your plot to look like? Specifically, how are you representing
>> color in a single column.
>
> For the color plot, I was looking for:
> Column 1 - x axis
> Column 2 - y axis
> Column 3 - color point (higher value = darker color)
>
> Good point... How would I do a plot3 with an increasing color variation
> with depth?

HELP SCATTER3

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Color / 3D plots

From: Paul

Date: 22 Jun, 2011 18:42:02

Message: 7 of 9

"Steven_Lord" <slord@mathworks.com> wrote in message <itro83$h0v$1@newscl01ah.mathworks.com>...
>
>
> "Paul " <palex71@hotmail.com> wrote in message
> news:itr4sc$i$1@newscl01ah.mathworks.com...
> > "Jeff " <jea@gene.dot.com> wrote in message
> > <itr2qo$o1r$1@newscl01ah.mathworks.com>...
> >> "Paul " <palex71@hotmail.com> wrote in message
> >> <itr1d6$k7h$1@newscl01ah.mathworks.com>...
> >> > Hello,
> >> > This should be farily easy...
> >> > I have a 1000x3 matrix. I am looking to do a color plot, where column
> >> > #1 defines the x axis, column #2 defines the y axis, and column #3 is
> >> > the color.
> >> >
> >> > I would also be interested in knowing how to do a 3D plot with the same
> >> > matrix.
> >> >
> >> > I haven't quite been able to figure out the proper command/syntax.
> >> >
> >> > Thanks!
> >>
> >> Can you give an example of your data, and a bit more description on what
> >> you want your plot to look like? Specifically, how are you representing
> >> color in a single column.
> >
> > For the color plot, I was looking for:
> > Column 1 - x axis
> > Column 2 - y axis
> > Column 3 - color point (higher value = darker color)
> >
> > Good point... How would I do a plot3 with an increasing color variation
> > with depth?
>
> HELP SCATTER3
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Thanks for the replies.
Here is a better indication on what I am trying to do with a 2d plot:

Matrix:
1 2 6
3 5 4
8 9 5

I need the x axis (column #1) scaled from 1 to 8
I need the y axis (column #2) scaled from 2 to 9
At (x,y) = (1,2), I need a point plotted of color value = 6 (darkest)
At (x,y) = (3,5), I need a point plotted of color value = 4 (lightest)
At (x,y) = (8,9), I need a point plotted of color value = 5 (middle)

Thanks again!

Subject: Color / 3D plots

From: Jeff

Date: 22 Jun, 2011 19:17:20

Message: 8 of 9

"Paul " <palex71@hotmail.com> wrote in message <ittd1q$ee9$1@newscl01ah.mathworks.com>...
> "Steven_Lord" <slord@mathworks.com> wrote in message <itro83$h0v$1@newscl01ah.mathworks.com>...
> >
> >
> > "Paul " <palex71@hotmail.com> wrote in message
> > news:itr4sc$i$1@newscl01ah.mathworks.com...
> > > "Jeff " <jea@gene.dot.com> wrote in message
> > > <itr2qo$o1r$1@newscl01ah.mathworks.com>...
> > >> "Paul " <palex71@hotmail.com> wrote in message
> > >> <itr1d6$k7h$1@newscl01ah.mathworks.com>...
> > >> > Hello,
> > >> > This should be farily easy...
> > >> > I have a 1000x3 matrix. I am looking to do a color plot, where column
> > >> > #1 defines the x axis, column #2 defines the y axis, and column #3 is
> > >> > the color.
> > >> >
> > >> > I would also be interested in knowing how to do a 3D plot with the same
> > >> > matrix.
> > >> >
> > >> > I haven't quite been able to figure out the proper command/syntax.
> > >> >
> > >> > Thanks!
> > >>
> > >> Can you give an example of your data, and a bit more description on what
> > >> you want your plot to look like? Specifically, how are you representing
> > >> color in a single column.
> > >
> > > For the color plot, I was looking for:
> > > Column 1 - x axis
> > > Column 2 - y axis
> > > Column 3 - color point (higher value = darker color)
> > >
> > > Good point... How would I do a plot3 with an increasing color variation
> > > with depth?
> >
> > HELP SCATTER3
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
>
> Thanks for the replies.
> Here is a better indication on what I am trying to do with a 2d plot:
>
> Matrix:
> 1 2 6
> 3 5 4
> 8 9 5
>
> I need the x axis (column #1) scaled from 1 to 8
> I need the y axis (column #2) scaled from 2 to 9
> At (x,y) = (1,2), I need a point plotted of color value = 6 (darkest)
> At (x,y) = (3,5), I need a point plotted of color value = 4 (lightest)
> At (x,y) = (8,9), I need a point plotted of color value = 5 (middle)
>
> Thanks again!

Give the following a try:

matin = [ 1 2 6; 3 5 4 ; 8 9 5; 4 4 10 ; 2 2 3];

scatter(matin(:,1), matin(:, 2), 100, matin(:,3), 'filled')
axis([0 10 0 10])
colormap(cool)

Check out the help section for colormap for a list of default maps, or to create your own. I scaled the axis a bit larger than the min/max for x and y, as one of the points was being clipped. You could remove this entirely, or use an expression like (min(matin(:,1) -1) to automatically scale this.

Subject: Color / 3D plots

From: Paul

Date: 23 Jun, 2011 17:25:20

Message: 9 of 9

"Jeff " <jea@gene.dot.com> wrote in message <ittf40$ktr$1@newscl01ah.mathworks.com>...
> "Paul " <palex71@hotmail.com> wrote in message <ittd1q$ee9$1@newscl01ah.mathworks.com>...
> > "Steven_Lord" <slord@mathworks.com> wrote in message <itro83$h0v$1@newscl01ah.mathworks.com>...
> > >
> > >
> > > "Paul " <palex71@hotmail.com> wrote in message
> > > news:itr4sc$i$1@newscl01ah.mathworks.com...
> > > > "Jeff " <jea@gene.dot.com> wrote in message
> > > > <itr2qo$o1r$1@newscl01ah.mathworks.com>...
> > > >> "Paul " <palex71@hotmail.com> wrote in message
> > > >> <itr1d6$k7h$1@newscl01ah.mathworks.com>...
> > > >> > Hello,
> > > >> > This should be farily easy...
> > > >> > I have a 1000x3 matrix. I am looking to do a color plot, where column
> > > >> > #1 defines the x axis, column #2 defines the y axis, and column #3 is
> > > >> > the color.
> > > >> >
> > > >> > I would also be interested in knowing how to do a 3D plot with the same
> > > >> > matrix.
> > > >> >
> > > >> > I haven't quite been able to figure out the proper command/syntax.
> > > >> >
> > > >> > Thanks!
> > > >>
> > > >> Can you give an example of your data, and a bit more description on what
> > > >> you want your plot to look like? Specifically, how are you representing
> > > >> color in a single column.
> > > >
> > > > For the color plot, I was looking for:
> > > > Column 1 - x axis
> > > > Column 2 - y axis
> > > > Column 3 - color point (higher value = darker color)
> > > >
> > > > Good point... How would I do a plot3 with an increasing color variation
> > > > with depth?
> > >
> > > HELP SCATTER3
> > >
> > > --
> > > Steve Lord
> > > slord@mathworks.com
> > > To contact Technical Support use the Contact Us link on
> > > http://www.mathworks.com
> >
> > Thanks for the replies.
> > Here is a better indication on what I am trying to do with a 2d plot:
> >
> > Matrix:
> > 1 2 6
> > 3 5 4
> > 8 9 5
> >
> > I need the x axis (column #1) scaled from 1 to 8
> > I need the y axis (column #2) scaled from 2 to 9
> > At (x,y) = (1,2), I need a point plotted of color value = 6 (darkest)
> > At (x,y) = (3,5), I need a point plotted of color value = 4 (lightest)
> > At (x,y) = (8,9), I need a point plotted of color value = 5 (middle)
> >
> > Thanks again!
>
> Give the following a try:
>
> matin = [ 1 2 6; 3 5 4 ; 8 9 5; 4 4 10 ; 2 2 3];
>
> scatter(matin(:,1), matin(:, 2), 100, matin(:,3), 'filled')
> axis([0 10 0 10])
> colormap(cool)
>
> Check out the help section for colormap for a list of default maps, or to create your own. I scaled the axis a bit larger than the min/max for x and y, as one of the points was being clipped. You could remove this entirely, or use an expression like (min(matin(:,1) -1) to automatically scale this.

Thanks Jeff...
That was what I needed.

Regards.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us