Scatter plot with matrix data

66 views (last 30 days)
Graeme
Graeme on 19 Jun 2012
Hi everyone,
I'm wondering if anyone can help with this problem. I am trying to create a scatter plot against axes x and y with the colours of the points reflecting a third z variable on a colour scale. In this case I have temperature, salinity and carbon content of a body of water. I am familiar with the 'scatter' function and this works well for single columns of data but the problem arises because my x and y data are a full matrix of values (rows corresponding to depths in the water and columns corresponding to different stations). Furthermore, because the depth is not the same everywhere, the length of the columns vary (with columns ending in NaNs where the data stops), though I'm not sure if this is what is causing the problem as it doesn't affect the ability to plot a simple x versus y plot with the usual 'plot' function. I am able to produce the correct plot by using a for-loop and plotting each column individually using 'scatter', however this takes a lot of computing power when trying to run the full dataset. Does anyone know an efficient way of running a scatter plot with a full matrix of values?
Any help would be greatly appreciated.
Kind regards,
Graeme
  1 Comment
Walter Roberson
Walter Roberson on 19 Jun 2012
I wonder if stem3() would be usable for you?

Sign in to comment.

Answers (2)

per isakson
per isakson on 19 Jun 2012
"a scatter plot against axes x and y with the colours of the points reflecting a third z variable on a colour scale." That is exactly what scatter does.
However, you want to present "temperature" as a function of x, y and z (depth) - or do I miss somehing? The function,
scatter3(X,Y,Z,S,C)
is intended for that.
How many points do you have? Could you supply a small example of the data?
  2 Comments
per isakson
per isakson on 19 Jun 2012
Certainly, this is just a copy from the documentation. It should be a minor problem to assign the appropriate values to X,Y,Z and C. However, why guessing about details of the input data.

Sign in to comment.


Walter Roberson
Walter Roberson on 19 Jun 2012
You indicate that your x and y are full matrices of data, but the rest of your description leads me to suspect that might not be correct in the way people are likely to understand you.
Do you have an actual x variable? If so, then what would (say) x(3,2) correspond to? And likewise if you have an actual y variable, what would y(3,2) correspond to? Are these grid coordinates (such as map coordinates) like x(3,2) is the latitude at which z(3,2) was measured and y(3,2) is the longitude of that point?
Or is it the case that you have no actual x and y variable, and that instead the first dimension of your z is associated with a particular depth, and the second dimension of your z is associated with the different stations? Or perhaps you do have an actual x but it is a vector of depths and your actual y is a vector of station identifiers, and z(3,2) would correspond to depth x(3) at station y(2) ?
If the coordinates are implicit or are each vector, then building the plot is relatively easy. If,though, there are distinct x(J,K) and y(J,K) for each coordinate pair J, K, then the plot takes a little bit more work.
  1 Comment
Graeme
Graeme on 20 Jun 2012
"Or perhaps you do have an actual x but it is a vector of depths and your actual y is a vector of station identifiers, and z(3,2) would correspond to depth x(3) at station y(2) ?" -------- This explanation seems to make the most sense. Let me try to explain my dataset more accurately.
I have three variables that I am trying to portray... Salinity, Temperature and Carbon. Each of these variables is arranged as a matrix, with the columns of the matrix corresponding to the station, and the rows of the matrix corresponding to the depth. Thus, for example, Salinity(3,2) is the salinity measured at station 3 and depth 2 and likewise for Temperature and Carbon.
I am trying to find an efficient way of plotting Salinity against Temperature in a scatter plot, with the colour of the points corresponding to the Carbon value.
I hope that makes a bit more sense...
As I said, I can create the plot using a for-loop, plotting each column of data in turn. Something like...
[m,n]=size(Salinity)
for i=1:n;
scatter(Salinity(:,i),Temperature(:,i),[],Carbon(:,i),'filled');
hold on;
end
As you can imagine, this takes a long time to compute when using the full data set.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!