How to Have Non-Zero Symbol for Incomplete Labels of XTicks in Matlab?

后端 未结 1 753
礼貌的吻别
礼貌的吻别 2020-12-21 19:03

I run into the problem where Matlab 2015b expands the labels of new Xticks when the x-axis gets bigger by using incomplete label, zeros, in the thread No Gap Next to Axis La

相关标签:
1条回答
  • 2020-12-21 19:46

    As I said in the other question, if you want the labels to be updated automatically when you resize things, you'll want to do the following.

    fig = figure;
    
    % Set large xlimits to demonstrate the issue at hand
    ax2 = axes('xlim', [0 1e9]);
    
    % Force a draw event to have the axes determine where the
    labelconverter = @(x)sprintf('%.2g', x);
    callback = @(varargin)set(ax2, 'xticklabels', arrayfun(labelconverter, get(ax2, 'xtick'), 'uniform', 0));
    
    set(fig, 'SizeChangedFcn', callback);
    
    % Be sure to execute the callback to get new labels prior to figure resize.
    callback();
    

    As you change the size of your figure, the labels will be changed automatically and the positions will be updated.

    Small Window

    Medium Window

    Large Window

    Note: Test this code in isolation to verify that it works, then adapt the idea to your solution. It seems like you're ending up with a lot of complications because your namespace is polluted (for example your examples don't even run because labels isn't defined).

    0 讨论(0)
提交回复
热议问题