45 views (last 30 days)
Show older comments
Pichawut Manopkawee on 26 Sep 2020
Commented: Pichawut Manopkawee on 27 Sep 2020
Accepted Answer: Cris LaPierre
- untitled.png
Hi All,
Could you giving a code or advice how to extract X,Y data from a scattered plot?
I have tried several ways following previous suggestions on website, none of that works for me.
I've attached the figure as what I want to extract those values out.
I strongly hope that one of you might help me solve this issue.
Thanks in advance,
Pete
4 Comments Show 2 older commentsHide 2 older comments
Show 2 older commentsHide 2 older comments
KSSV on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025518
You want to extract those values from the atatched .png file?
Pichawut Manopkawee on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025671
Edited: Pichawut Manopkawee on 26 Sep 2020
Hi
Actually, I plot them from two matrix files. However, they have a huge number that I do not know which point represents x,y data. I focus on only the data that less than 100 m2. So, I would like to get y data on those point below 100 m2.
Cris LaPierre on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025710
If you haved the data used to create the plot, there are better ways of doing this. You can figure out what X is from the plotting code. What is you plot command?
Pichawut Manopkawee on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025728
This is a plot command
semilogx(saproduct,laplacian,'k.','markersize',8);
saproduct and laplacian are two matrix containing values of 756x519 single
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Cris LaPierre on 26 Sep 2020
Open in MATLAB Online
Assuming you have a *.fig file and not a .png, first open the fig file in MATLAB then run the following code.
s=findobj(gca,'Type','Scatter');
X = s.XData;
Y = s.YData;
6 Comments Show 4 older commentsHide 4 older comments
Show 4 older commentsHide 4 older comments
Pichawut Manopkawee on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025677
Hi,
When I run the first code, s doesn't have any properties or values associated. It says 0x0 GraphicsPlaceholder.
Also, when I run the second and third codes you provided, I get these messages from MATLAB.
'unrecognized method, property, or field 'XData' for class 'matlab.graphics.GraphicsPlaceholder'
'unrecognized method, property, or field 'YData' for class 'matlab.graphics.GraphicsPlaceholder'
Cris LaPierre on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025719
Edited: Cris LaPierre on 26 Sep 2020
Open in MATLAB Online
I feel like we're missing some details. Did you have the figure window open when you ran the code? Is your figure created using the scatter function or did you use plot? I assumed scatter. Here's a full working example using plot.
plot([1:5],[10:14],'o');
s=findobj(gca,'Type','Line')
x = s.XData;
y = s.YData;
x =
1 2 3 4 5
y =
10 11 12 13 14
You could do something similar if your plot was created using scatter
scatter([1:5],[10:14]);
s=findobj(gca,'Type','Scatter')
x = s.XData;
y = s.YData;
x =
1 2 3 4 5
y =
10 11 12 13 14
Cris LaPierre on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025734
Edited: Cris LaPierre on 26 Sep 2020
Open in MATLAB Online
Of course, if you are creating the plot yourself, this could be simplified using a handle.
L = plot([1:5],[10:14],'o');
X = L.XData;
Y = L.YData;
Of course, if the point is to capture the x and y values, it would make more sense to do this.
X = 1:5;
Y = 10:14;
plot(X,Y,'o')
Pichawut Manopkawee on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025737
Because it is a semilog plot, so I don't use scatter or plot. Here I used
semilogx(saproduct,laplacian,'k.','markersize',8);
saproduct and laplacian are two matrix containing values of 756x519 single.
They contain huge numbers
Cris LaPierre on 26 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1025773
Edited: Cris LaPierre on 26 Sep 2020
Open in MATLAB Online
Now we're getting somewhere! When passed matrices, MATLAB will plot each column as its own series. That means your semilogx plot is made up of 519 data series with 756 data pairs in each one. Since you are setting your marker color, you probably noticed that (each series is assigned a different color). To extract the data from the figure, you would have to loop through each line object, combining the data as you go.
Luckily, since you have the data and are creating the plot, we don't have to do that. We can use linear indexing instead to create the exact same semilogx plot, but with all the data in a single series. This makes it easier to figure out the [X,Y] pairing. Linear indexing turns both matrices into column vectors by stacking the columns on top of each other (column 2 is directly under column 1, etc).
X = saproduct(:);
Y = laplacian(:);
semilogx(X,Y,'k.','markersize',8)
X and Y are vectors with size 392364 x 1.
Pichawut Manopkawee on 27 Sep 2020
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/600217-extract-x-y-data-from-scatter-plot#comment_1026223
Thank you so much Cris LaPierre
Sign in to comment.
More Answers (0)
Sign in to answer this question.
See Also
Categories
MATLABGraphics2-D and 3-D PlotsData Distribution PlotsScatter Plots
Find more on Scatter Plots in Help Center and File Exchange
Tags
- scattered data
- extract value
- plot
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office