How can I assign multiple colors to tick labels in plots in MATLAB?

后端 未结 3 1067
耶瑟儿~
耶瑟儿~ 2020-12-19 13:33

Is it possible to color a single number (or a set of numbers) on one of the axes in MATLAB?

Suppose I have a plot:

plot(1:10, rand(1,10))
         


        
3条回答
  •  别那么骄傲
    2020-12-19 13:36

    As an alternative to copying the entire axes contents, it is possible to do this also by creating additional axes objects:

    ax = axes();
    p = plot(1:10, rand(1,10));
    myTick = 3;
    
    % Create new axes with transparent backgrounds
    ax2 = axes();
    ax3 = axes();
    set([ax2 ax3], 'XLim', xlim(ax));
    set([ax2 ax3], 'Color', 'none');
    
    set(ax3, 'XTick', [], 'YTick', []);
    
    % Give one new axes a single tick mark
    set(ax2, 'YTick', []);
    set(ax2, 'XTick', myTick);
    set(ax2, 'XColor', 'r');
    
     % This line is necessary to use the plot toolbar functions like zoom / pan
    linkaxes([ax ax2 ax3]);
    

提交回复
热议问题