2

我有很多图表。我需要对这些图表进行一些格式化。就像我需要更改标签,画几条线然后放置图例,在所有这些图表上格式化字体大小和颜色等。这些图表是 .fig 文件。

我没有图形数据点,并且生成代码选项需要很长时间才能处理。这些图是散点图。

有没有办法可以对所有这些图表使用相同的格式。喜欢打开所有无花果并通过编码进行一些图形属性编辑?或创建格式并可以应用于所有数字?(类似格式漆的东西)

谢谢

4

2 回答 2

1

MATLAB 图形是复杂的分层对象,因此几乎不可能制作通用的“格式画家”。

您可以将图形、轴、线等的属性作为结构获取,但其中许多是只读的。

如果您正在处理简单的图形 - 一个轴,相似类型的图,相同数量的数据系列,没有手动注释 - 可能更简单的方法是从一个图形中获取数据并将它们应用于您想要用作图形的图形标准。

如果您的图形都是散点图,则对象类型是线(如果使用绘图)或 hggroup(如果使用散点图)。所以他是如何做到这一点的一个例子。

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
于 2012-02-08T17:57:22.537 回答
1

如果我理解正确,您应该能够一次打开一个数字,然后应用所需的格式。就像是:

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
于 2012-02-08T17:59:06.547 回答