Suppress exponential formatting in figure ticks

后端 未结 3 1302
余生分开走
余生分开走 2020-11-28 13:10

Tick labels for ticks bigger than about 10\'000, get formatted to 1x10^4 for example. Whereas the exponential part appears above the corresponding axes. This misbehavior has

3条回答
  •  盖世英雄少女心
    2020-11-28 13:32

    EDIT

    According to this technical solution page, the recommended way of formatting the tick labels is this (you can use any of the number formatting functions like NUM2STR, SPRINTF, MAT2STR, or any other..)

    y = cool(7);
    bar(y(:,1)*1e6)
    set(gca, 'YTickMode','manual')
    set(gca, 'YTickLabel',num2str(get(gca,'YTick')'))
    

    alt text

    However there seems to be a bug when it comes to the Z-axis (the labels are correctly formatted, but the exponential multiplier is still showing for some reason!)

    y = cool(7);
    bar3(y*1e6, 'detached')
    set(gca, 'ZTickMode','manual')
    set(gca, 'ZTickLabel',num2str(get(gca,'ZTick')'))
    

    alt text

    Finally, there's another workaround where we replace the tick labels with text objects (see this technical solution page as reference):

    y = cool(7);
    bar3(y*1e6, 'detached')
    offset = 0.25; Xl=get(gca,'XLim'); Yl=get(gca,'YLim'); Zt=get(gca,'ZTick');
    t = text(Xl(ones(size(Zt))),Yl(ones(size(Zt)))-offset,Zt, num2str(Zt')); %#'
    set(t, 'HorizontalAlignment','right', 'VerticalAlignment','Middle')
    set(gca, 'ZTickLabel','')
    

    alt text

提交回复
热议问题