Search code examples
matlab

Force axes to initialize before plotting


I seek to remove borders using this solution, where pause doesn't work.

plot([1 2])
ax = gca;
ax.XRuler.Axle.LineStyle = 'none';

throws

Property assignment is not allowed when the object is empty.
Use subscripted assignment to create an array element.

Here, pause works, but in my context (large tiledlayout) let's say[*] it doesn't. Replacing last line with ax.XRuler.Axle gives

  0×0 empty GraphicsPlaceholder array.

With pause, it gives

LineStrip

I presumed the error message is suggesting subsasgn, which I've tried, but it's two . accesses. I've not found the LineStrip object anywhere.

Are there any hacks to this situation? Or better solutions (I can re-title the question)? The goal is to simply make the borders disappear, without disabling xlabel & ylabel.

[*] pause(.01) greatly slows down everything for some reason, also some tiles are skipped (on purpose), though I suppose I could hack that part with another slowdown


Solution

  • It seems that the problem is that the command ax=gca is executed before the graphic engine can create the plot, as the graphic engine is called asynchronously from the executing of the script.

    If your problem is that the equivalent plot command takes too long before the axis can be handled, a possible solution is to force an axis creation (very fast) and then plot in that axis after tuning it.

    axes
    drawnow % you still need this, but should not slow anything down, as the axes call should be very fast
    ax = gca;
    ax.XRuler.Axle.LineStyle = 'none';
    plot([1 2])
    

    For tiledlayout:

    figobj = tiledlayout(2, 3);
    for i=1:prod(figobj.GridSize)
        nexttile
    end
    drawnow
    % do plotting ...