gplotmatrix with continuous 3rd parameter

Hi,
I would like to plot a gplotmatrix, but instead of coloring the marks according to grouping variables (eg. [1, 2, 3, 4]) with distinct colors I would like to color them depending on a 3rd continuous parameter (eg. [1 1.01 1.02 .... 3.99 4]) using a colormap like jet.

 Accepted Answer

gplotmatrix() is not able to do that. The scatter-looking plots that gplotmatrix() creates are not scatter objects: they are line objects. line objects cannot have different colors for different points.
You could, hypothetically, use gplotmatrix() to create the data, and then loop through the returned line objects (first output), replacing each line with a scatter plot using the same information but setting CData as appropriate. You would have to figure out what the source and destination columns are for each object in order to pick out the appropriate continuous information to use as the colour.

4 Comments

Thank you for your answer. I think my knowledge of the different figure object classes is not sufficient to understand what you mean though. How can they be line objects? In the Matlab help it says they are 'a matrix of scatter plots' and that's what it looks like to me. I'd be happy to understand better what the difference actually is.
I found another easy way around it though, by simply parting my continuous data into closely spaced bins and creating my own colormap with as many colors as there are bins.
I agree that the help uses the term "scatter plots", but for whatever reason they are internally implemented as Primitive Line objects with LineStyle 'none'; https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.line-properties.html
When you use
h = gplotmatrix(...)
then h will become C x C x 2 array of line objects, where C is the number of columns in the data.
Any one line object can have only a single color and line style and marker and marker size. When the line style is 'none' then only the marker is used without any joining lines, creating the appearance of a scatter plot.
scatter objects can have a different colors and different marker sizes for each point, but only one marker shape, and cannot have any joining lines.
For small number of points, a line object can have performance advantages.
Thank you for the detailed explanation! Starts to make sense. So when it plots the n groups of data in the gplotmatrix with n colors, does it then just overlay n lineplots with LineStyle 'none' with different colors above one another?
Yes, that is correct.
Earlier I said that it returns C x C x 2. I should have said C x C x G where G is the number of groups.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!