Home > Blockchain >  Pull the scale used for X and Y ticks from a figure
Pull the scale used for X and Y ticks from a figure

Time:03-02

I'm working on a large project that generates hundreds of figures. We're trying to save the figure data to an external file. We're in the initial steps of it, we're finding figures being created and opening them to try and see what data is accessible. We're using

set(fHandle,'CreateFcn','set(gcf,''Visible'',''on'')')
savefig(fHandle, 'eg.fig')
fig = openfig('eg.fig')

to save the current figure and open it up. The figure has changed the X and Y ticks to different strings that are vitally important if we want to save the figure data. Is there a way to view the data used for ticks with just the fig? I've looked all throughout the figure and I couldn't find anything relating at all.

CodePudding user response:

The question is not quite clear about what exactly is being sought. I am assuming it is the labels on the axes. If you have a handle to a figure (even one opened from a file) you can view the tick labels using the Children property. E.g. to see the X axis tick labels:

fig.Children.XTickLabel

Fully working example:

x = linspace(-10,10,200);
y = cos(x);
fHandle = figure;
plot(x,y);
xticks([-3*pi -2*pi -pi 0 pi 2*pi 3*pi])
xticklabels({'-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi'})
yticks([-1 -0.8 -0.2 0 0.2 0.8 1])
savefig(fHandle, 'eg.fig');
fig = openfig('eg.fig');
fig.Children.XTickLabel

Output:

ans =

  7×1 cell array

    {'-3\pi'}
    {'-2\pi'}
    {'-\pi' }
    {'0'    }
    {'\pi'  }
    {'2\pi' }
    {'3\pi' }
  • Related