代码之家  ›  专栏  ›  技术社区  ›  zellus

抑制图形记号中的指数格式

  •  13
  • zellus  · 技术社区  · 15 年前

    on matlab central 也是,但没有解决办法。

    谢谢你的帮助。


    “快速技巧”

    set(gca, 'YTickLabel',get(gca,'YTick'))
    

    应用于bar3时不起作用,如下图所示。

    bar3 plot failing

    3 回复  |  直到 11 年前
        1
  •  1
  •   Jonas    15 年前

    一种更好地控制记号标签并避免指数格式的方法是使用 TICK2TEXT 从文件交换。

    举个例子:

    y = cool(7); %# define some data
    ah = axes; %# create new axes and remember handle
    bar3(ah,y*1E6,'detached'); %# create a 3D bar plot
    tick2text(ah, 'ztickoffset' ,-1.15,'zformat', '%5.0f', 'axis','z') %# fix the tick labels
    
        2
  •  10
  •   Amro    15 年前

    根据这个 technical solution page

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

    alt text

    但是,在Z轴上似乎有一个bug(标签格式正确,但指数乘数由于某些原因仍在显示!)

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

    alt text

    最后,还有另一种解决方法,我们用文本对象替换记号标签(参见此图) technical solution page 作为参考):

    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

        3
  •  3
  •   gnovice    15 年前

    LOG10 帮助您根据打印的值自动计算适当的比例因子。假设你的数据是变量 x y

    scale = 10^floor(log10(max(y)));  %# Compute a scaling factor
    plot(x,y./scale);                 %# Plot the scaled data
    yTicks = get(gca,'YTick');        %# Get the current tick values
    set(gca,'YTickLabel',num2str(scale.*yTicks(:),'%.2f'));  %# Change the labels