Separating an undetermined cell plot
Mostrar comentarios más antiguos
Hello, I have run into a wall in my code. I am trying to write a function that will take a figure and split the plotted graphs into separate figures. I have an idea of how to do this, but I cannot understand how to split the data I receive from the figures. Can anyone help? I've tried writing a for loop and using cellfun but I can't seem to get it to work.
Here's my code: My goal is to be able to split any size cell into individual cells.
separate_fig('filename')
f = openfig('filename','new','invisible'); %Sets input figure as current without opening it
H = findobj(f, 'type', 'line');
x_data = get(H, 'xdata');
y_data = get(H, 'ydata');
i = cell2mat(x_data); %Data from figure converted from cell into normal array.
j = cell2mat(y_data);
9 comentarios
Walter Roberson
el 13 de Jun. de 2018
Does the figure have multiple axes (subplot) and each subplot is to be made into its own figure?
Does the figure have any legend or colorbar objects? If so then we will need to know if you are using R2014b or later, or an earlier version.
manta24
el 13 de Jun. de 2018
Walter Roberson
el 13 de Jun. de 2018
The code you posted is headed in the direction of making every single primitive line object into its own figure. It seems unlikely you would want to do that, as it is very common for there to be multiple primitive line objects that need to be considered together, since a single primitive line object can only have one color and one marker shape (and one marker color.) Most plots are composite plots -- for example a contour plot involves a lot of internal line objects (though implemented differently than primitive line objects.)
manta24
el 13 de Jun. de 2018
Walter Roberson
el 13 de Jun. de 2018
Shrug. You have not given enough information about what should be kept on the same plot. Breaking up by axes would be plausible, as long as plotyy() or equivalent was not used to have multiple overlapping axes.
There might be some semi-tricky parts to move colorbar and legend properly but I don't think it should be too bad.
manta24
el 13 de Jun. de 2018
Walter Roberson
el 16 de Jun. de 2018
Editada: Walter Roberson
el 16 de Jun. de 2018
You are getting the data from an existing figure, but you are getting all of it at the same time. To avoid that, we need more information about the data hierarchy. For example, do you need to split axes by axes, each axes becoming a new figure? Or do you need to reach into axes and extract some kind of groupings of lines or surfaces, somehow breaking those out from others in the same axes?
A diagram would help.
Greg
el 19 de Jun. de 2018
Why are you trying to do this?
(Normally, I won't ask why; people tend to get defensive and off-topic. However, sometimes asking why rather than please elaborate gets us better information toward the root of the problem).
manta24
el 19 de Jun. de 2018
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!