Question

I have a number of graphs. I need to do some formatting over those graphs. Like i need to change labels, draw a few lines then place the legends,format the font size and colors etc over all those graphs. These graphs are .fig files.

I do not have the graph data points and generate code option is taking a very long time to process. And the plots are scatter plots.

Is there a way I can use the same formatting over all these graphs . Like open all the figs and do some figure property editing by coding ? or create a formatting and can apply over that over all the figures ? (smthing like format paint )

Thanks

Was it helpful?

Solution

MATLAB figures are complex hierarchical objects, so it would be almost impossible to make a universal "format painter".

You can get the properties of figure, axes, line, etc as a structure, but many of them are read-only.

If you are dealing with simple figures - one axes, similar types of plots, same number of data series, no manual annotations - probably the easier way would be get the data from one figure and apply them to the figure you want to use as a standard.

If your figure are all scatter, the object type is either line (if you use plot), or hggroup (if you use scatter). So he is an example how it can be done.

fstd = hgload('standard.fig'); %# load standard figure
f1 = hgload('f1.fig'); %# load another figure
%# find data series objects
hstd = findobj(gcf,'type','line','-or','type','hggroup');
h1 = findobj(gcf,'type','line','-or','type','hggroup');
assert(numel(hstd)==numel(h1),'Figures have different number of data series')
%# get the data coordinates from one figure and apply to another
for k = 1:numel(hstd)
    h1x = get(h1(k),'XData');
    h1y = get(h1(k),'YData');
    h1z = get(h1(k),'ZData');
    set(hstd(k),'XData',h1x);
    set(hstd(k),'YData',h1y);
    set(hstd(k),'ZData',h1z);
end
hgsave(hstd,'f1mod.fig') %# save the modified figure

OTHER TIPS

If I understand correctly you should be able to simply open the figures one at a time, and then apply the desired formatting. Something like:

fileList = dir('*.fig')
for ix = 1:length(fileList)
    h = open(fileList(ix).name);

    %Now operate on the figure with handle h
    %e.g.
    axis(h,[0 10 -3 3]);
    legend(h,'Data1','Data2');
    hold on
    plot(-10:10, x.^2,'k-'); 

    %Then get whatever output you want, e.g. save, print, etc.
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top