Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Plotting in different colors

Subject: Plotting in different colors

From: Swaprava Nath

Date: 26 Nov, 2007 18:54:28

Message: 1 of 3

I have some points to plot on a 2D plane. The points can be
classified into a number of categories, e.g., say 100
categories. I want the points of each of the categories to
have same color while differing from category to category.
Is there any way to plot this in a single figure? I tried to
understand how colormap works, but couldn't figure it out.
Thanks in advance for anyone who comes forward.

Subject: Plotting in different colors

From: Aaron Callard

Date: 26 Nov, 2007 19:18:39

Message: 2 of 3

I often end up doing this, the trick is to use the 3rd
input to plot see the code example below

colors=['b';'g';'r';'c';'m';'y';'k'];
markers=['.';'o';'x';'+';'*';'s';'d';'v'];
lines=['- ';': ';'-.';'--';' '];
variable1used=[1:4];
variable2used=[1:5];
for i=variable1used
    for j=variable2used
        x=squeeze(xdata(i,j,:));
        y=squeeze(ydata(i,j,:));
        plot(x,y,[colors(i) lines(j,:)])
        hold on
    end
end

that'll print all the variable1 with the same color and
all the variable 2 with the same line. You can add
another variable for different marker styles.
"Swaprava Nath" <swaprava@gmail.com> wrote in message
<fif4p4$mel$1@fred.mathworks.com>...
> I have some points to plot on a 2D plane. The points can
be
> classified into a number of categories, e.g., say 100
> categories. I want the points of each of the categories
to
> have same color while differing from category to
category.
> Is there any way to plot this in a single figure? I
tried to
> understand how colormap works, but couldn't figure it
out.
> Thanks in advance for anyone who comes forward.

Subject: Plotting in different colors

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 26 Nov, 2007 19:21:00

Message: 3 of 3

In article <fif4p4$mel$1@fred.mathworks.com>,
Swaprava Nath <swaprava@gmail.com> wrote:
>I have some points to plot on a 2D plane. The points can be
>classified into a number of categories, e.g., say 100
>categories. I want the points of each of the categories to
>have same color while differing from category to category.
>Is there any way to plot this in a single figure? I tried to
>understand how colormap works, but couldn't figure it out.
>Thanks in advance for anyone who comes forward.

scatter(X,Y,S,C)

where S is the marker size
and C is the color vector. You could make C the category number for
each point, or you could make C a matrix of RGB triples giving
the exact color you want for each point.

--
   "I was very young in those days, but I was also rather dim."
   -- Christopher Priest

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
plotting in different colors Swaprava Nath 26 Nov, 2007 13:55:21
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics