Extract X,Y data from scatter plot

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 comentarios

KSSV
KSSV el 26 de Sept. de 2020
You want to extract those values from the atatched .png file?
Pichawut Manopkawee
Pichawut Manopkawee el 26 de Sept. de 2020
Editada: Pichawut Manopkawee el 26 de Sept. de 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
Cris LaPierre el 26 de Sept. de 2020
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
Pichawut Manopkawee el 26 de Sept. de 2020
This is a plot command
semilogx(saproduct,laplacian,'k.','markersize',8);
saproduct and laplacian are two matrix containing values of 756x519 single

Iniciar sesión para comentar.

 Respuesta aceptada

Cris LaPierre
Cris LaPierre el 26 de Sept. de 2020
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 comentarios

Pichawut Manopkawee
Pichawut Manopkawee el 26 de Sept. de 2020
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
Cris LaPierre el 26 de Sept. de 2020
Editada: Cris LaPierre el 26 de Sept. de 2020
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
Cris LaPierre el 26 de Sept. de 2020
Editada: Cris LaPierre el 26 de Sept. de 2020
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
Pichawut Manopkawee el 26 de Sept. de 2020
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
Cris LaPierre el 26 de Sept. de 2020
Editada: Cris LaPierre el 26 de Sept. de 2020
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
Pichawut Manopkawee el 27 de Sept. de 2020
Thank you so much Cris LaPierre

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by