0
votes

I am generating many (thousands) of plots using very large data. I need a very simple way to make my markers different colors, but each element needs to keep it's color. In my main for loop I have:

for i = 1:finaltime plot(pos(i,:), track(i,:), 'o', 'MarkerSize', 9) ;

Where "pos" tells the position of the element (there are 1000) and "track" specifies the track number the element is on (there are 4). So I need 1000 different colors for each marker (which corresponds to each column) in the matrix "pos", which is finaltime by 1000 in size. For every figure generated (there will be finaltime of them), I'd like the 1000 elements to maintain their colors. For example, the first element in "pos" is blue throughout the simulation. The second element is red, etc.

2
you probably can generate the RGB values for the colors separately then paste them into an array in your code. even a simple python script to output RGB values - chris
Perhaps you can generate a colour map (colormap) with 1000 entries, then pick off a row / colour for each track you want to plot. - rayryeng
OK, now I get it. Is it my understanding that you would like each column of pos and corresponding column of track to be assigned to the same colour? Basically, each row of pos and track has 1000 points, where each point should be assigned a different colour. For each row that you plot, you want to make sure that the colour scheme is the same for all rows. If that's the case, then you need to plot the columns and apply the colour map accordingly. - rayryeng
Do you require any further assistance? - rayryeng

2 Answers

3
votes

One suggestion I have is to generate a colour palette that is 1000 elements, then for each set of observations you have, simply set the marker to one colour within this colour palette.

If I understand you correctly, you have a matrix where each pair of columns for pos and track are to have unique colours. Basically, each row of pos and track has 1000 points, where each point should be assigned a different colour. For each row that you plot, you want to make sure that the colour scheme is the same for all rows. If that's the case, then you need to plot the columns and apply the colour map accordingly.

As such, do something like this:

c = jet(1000);
figure; hold on;
for idx = 1 : 1000
    plot(pos(:,idx), track(:,idx), 'o', 'MarkerSize', 9, 'Color', c(idx,:));
end

jet is the MATLAB command that generates a colour map default to MATLAB (pre-2014).

There are other colour maps you can explore, and the full list is shown here:

If you want to use another colour map, simply use the name and call it as a function, with an integer as an input. This integer will give you that many colours within the confines of that colour map. As such, say if you wanted the hsv colour map with 256 colours. You would do this:

c = hsv(256);
0
votes

I found the answer is actually very easy... if I just use scatter instead of plot, the scatter function can take in an array of colors, whereas plot can only take one color at a time. So I just changed the code to:

scatter(pos(i,:), track(i,:), c );

Where c = rand(n,3) and specifies the colors. Thanks!