Change colours of specific points in a scatter plot that has already been plotted?

I have a dimensionality reduction algorithm that extracts latent variables from a dataset and visualises one latent variable with three subplots. The third of the three subplots is a scatter plot, and I want to change the colours of some of the points in this scatter plot.
I know what the indexes of the points that I want to change the colour of are, but I cannot just plot one set one colour and then another set another colour, because the plots are generated from a 3rd order tensor, and are not just datapoints.
Hence I ask: is it possible for me to change colours the datapoints in the plot, after they have been plotted?

5 Comments

If you have indices.....using the indices specify your required color using plot command.
Thanks for the response.
Would you be able to give me a rough example? Also, would it be any different doing this in a subplot?
Do you know these indices a priori or only after the plot already done and then they're somehow determined?
If you know them at the time the plot(), use scatter() and a color vector of the length of the variable...if you use plot(), then all elements in one call are the same line and ergo have the same linestyle and color so can't change them individually.
I don't understand the part about the tensor; you've got to get the coordinates for plotting at some point, so why can't those be saved and plotted as wanted at will?
I know the indices a priori, but I don't know the values that the datapoints are going to be until after I generate the plot.
Let me show the code to make this a bit clearer:
% M is a special type of array that contains special variables.
% Put simply, it isn't just the datapoints that I want
load('output_last.mat', 'M');
% This is a function from the tensor toolbox, it extracts out the datapoints that
% I want to plot from M.
[info] = viz_ktensor(M, ...
'Plottype', {'bar', 'line', 'scatter'}, ...
'Modetitles', {'neurons', 'time', 'trials'}),...
set(gcf, 'Name', ['estimated factors - fit #' num2str(n)])
The output is this:
I am focusing on the scatter plots on the far right here.
Do you see how I have to put my dataset into this black box called "viz_tensor" in order to get my plots?
So, I want to change the colours of certain datapoints on these scatter plots on the right hand side.
E.g. I know that in the 250 datapoints that I have, that I want 3, 7, 10... etc to all be green. But, because the datapoints come from a model, I don't know the value that they take on until after the plot.
I have the scatter plot, and I have the indices, so all I want to do is change the colours of datapoints on the plot for those specific indices.
Update: figured it out. The output of the function "info" contains information of X and Y data for the plots so I can use these.
Apologies for the confusing question and thanks all for the help!

Sign in to comment.

 Accepted Answer

Take a look at gscatter().

2 Comments

This does look like it would be useful, but I dont know how to use this when I only have my datapoints after I have plotted them. The plots that I get come out of a toolbox that I would have to dig in to the change the scatters that are generated.
I can look at the information inside the generated scatter plot to see what the X and Y data are that are plotted, so how can I use this data inside gscatter?
You can first extract XData and YData of the figure you want, then create a grouping variable, where, for example, intact points are in group 1 and recolored points are in group 2, then you clear the axes, and draw your own scatter plot using gscatter().
Ax = subplot (3,3, 3);
X = Ax.Children(1).XData;
Y = Ax.Children(1).YData;
Grouping = ones (NumPoints,1);
Grouping (RecoloredPointsIndexes) = 2;
cla;
GscatterHdl = gscatter (X,Y,Grouping);
GscatterHdl(1) = 'b';
GscatterHdl(2) = 'g';
Next you do the same for
Ax = subplot (3,3, 6);
and
Ax = subplot (3,3, 9);

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!