Extract data from figure with multiple axes

Hi,
I want to extract data from a figure which I have created using "tightplot" ( https://uk.mathworks.com/matlabcentral/fileexchange/45380-tightplots ). The function generates different cooradinate systems using axes.
I now want to extract the data from the figures. I tried this ( https://uk.mathworks.com/matlabcentral/answers/177990-how-do-i-pull-data-from-a-figure-with-multiple-plots ) but it does not work.
Here is an example of the figure:
figure;
ha=tight_subplot(2,2,0.08,[0.1000,0.0250],[0.08,0.025]);
%plot1
axes(ha(1));
plot(1:10);
%plot2
axes(ha(2));
plot(-1:-1:-10);
%plot3
axes(ha(3));
plot(1:10);
%plot4
axes(ha(4));
plot(-1:-1:-10);

2 Kommentare

Adam
Adam am 6 Aug. 2019
Do you not have the original data any more? It's a lot easier to keep the actual data than to start extracting it from plots. I haven't used tightplots, but its outputs appear to be all the axes handles so surely it is just a case of getting XData, YData, CData or whatever you want from each of these axes handles?
dpb
dpb am 6 Aug. 2019
Agree w/ Adam; just iterate through the hA array, retrieving the .Children handle(s) for each and then the subsequent .X|YData thereof.
Or, you could use findobj to get the 'Line' objects for the axes; eeny-meeny which way to go...

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Chris
Chris am 6 Aug. 2019

0 Stimmen

I am not quite sure what you mean. Can you give an example?

3 Kommentare

It really depends what is on the axes and whether you knnow in advance what is on each given axes.
But
ch = get( ha(1), 'Children' )
will give you a list of the graphics objects on the first axes.
ch(1).XData
ch(1).YData
would give you the XData and YData from the first child, assuming it is something like and image or line plot which has these properties.
Chris
Chris am 6 Aug. 2019
Thanks! Got it. And how can I get the ha, if I only have the figuere?
Not very adventurous, are you??? :)
hF=gcf;
hAx=hF.Children; % presuming there are axes extant, of course
or,
hAx=findobj(hF,'Type','axes');

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 6 Aug. 2019

Kommentiert:

dpb
am 6 Aug. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by