Scatter plot with matrix data
31 views (last 30 days)
Show older comments
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
Answers (2)
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
Walter Roberson
on 19 Jun 2012
scatter() takes _vectors_ of x and y and z, not _matrices_ of x and y and z.
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.
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.
See Also
Categories
Find more on Scatter 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!