开发者

Why won't this axes object display correctly in MATLAB?

I am writing two small psychoacoustic testing applications in MATLAB. The first one works without problems but the second one doesn't, and I just can't figure out why.

Here is the problem: the axes object is created, but it is empty.

failed_axis http://dl.getdropbox.com/u/98854/help.png

Here is the code that creates this figure and axes:

hFig = figure('dockcontrols','off','menubar','none', ...
              'name','choose the better sounding file', ...
      'numbertitle','off','position',[0,0,700,500], ...
      'resize','off','toolbar','none','units','normalized', ...
      'color',[.8,.8,.8]);
progress_idc = axes('position',[.1,.8,.8,.05],'box','on','parent',hFig,...
            'xlim',[-.03,1.03],'xtickmode','manual','xtick',[], ...
            'xticklabelmode','manu开发者_运维百科al','xticklabel',[], ...
            'ylim',[-1,1],'ytickmode','manual','ytick',[], ...
            'yticklabelmode','manual','yticklabel',[], ...
            'nextplot','add');

And here is the code that plots in this axes (the function is called regularly by a timer):

function replot(varargin) % this is a nested function
    cla;

    % plot start_indicator
    plot([x_start,x_start],[-.7,.7],'k','linewidth',2);
    fill([x_start,x_start-.02,x_start-.02],[0,-.7,.7],[0,0,0]);

    % plot stop_indicator
    plot([x_stop,x_stop],[-.7,.7],'k','linewidth',2);
    fill([x_stop,x_stop+.02,x_stop+.02],[0,-.7,.7],[0,0,0]);

    % plot play_position
    plot([x_play,x_play],[-1,1],'r');

    drawnow;
end

This is what it looks like if it works:

proper_axis http://dl.getdropbox.com/u/98854/help2.png

Do you have any idea what is going wrong here?


I ran the code you included above and got the correct output.

If I had to take a wild guess as to what the problem is, I'd guess that you may be creating other axes in your application that you are not listing above, or that you may have other axes not related to the application open at the time the application is running. When you plot your objects in the function replot, you are by default plotting them to the currently active axes. If you have multiple axes open, the plotting may therefore be going on in the wrong set of axes.

One suggestion I would make is to explicitly specify what the parent axes object should be in your calls to PLOT and FILL. If you add the arguments ...,'Parent',progress_idc); to your plotting calls, it will ensure that the correct axes is always used. I make a habit of always specifying the parent axes object instead of assuming that the currently active axes will always be the one I need it to be.


I finally found the (dumb) answer. The title accidentally had the same position as the plot axis. Due to some rendering-details of Matlab, it obscures the whole axis except for the rightmost and bottommost line of pixels, which makes the axis look "empty".

Oh, what a dumb error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜