【问题标题】:Is it possible for tick marks on an image to be centered around the -edge- of a pixel?图像上的刻度线是否可以以像素的边缘为中心?
【发布时间】:2011-02-09 00:42:15
【问题描述】:

如果我在 Matlab 中使用 image() 命令制作一个 4 x 4 像素的图像,它会将刻度线居中在像素的中间。我希望刻度线位于像素的左下角。有没有办法做到这一点?

【问题讨论】:

    标签: image matlab plot center axis-labels


    【解决方案1】:

    尝试以下方法:

    a = randi([0 255], [4 4]);
    figure, imagesc(a), caxis([0 255])
    
    b = zeros( size(a)+1 );
    b(1:end-1,1:end-1) = a;
    figure, pcolor(b), caxis([0 255]), axis ij
    

    请注意,我扩展了矩阵 a,因为 pcolor 删除了最后一行/列。

    【讨论】:

      【解决方案2】:

      我认为这段代码会做你想做的事。它只在像素的边缘放置刻度线:

      A = ...;  %# Your 4-by-4 matrix
      image([0.5 3.5],[0.5 3.5],A);      %# Pixel edges are at 0, 1, 2, 3, and 4
      set(gca,'XTick',0:4,'YTick',0:4);  %# Place tick marks at 0, 1, 2, 3, and 4
      

      【讨论】:

        【解决方案3】:

        您可以指定像素的 x 和 y 坐标并将它们移动 0.5:

        image([0.5,3.5],[0.5,3.5],magic(4))
        

        【讨论】:

        • 我之前尝试过,但仍然缺少 0 的刻度,如果它与常规图形并排,它看起来就不那么好了。
        • @Wires:这很奇怪。在左下角,x 轴为 0,y 轴为 4。
        猜你喜欢
        • 1970-01-01
        • 2020-01-14
        • 1970-01-01
        • 2021-10-14
        • 2019-06-20
        • 1970-01-01
        • 2017-04-01
        • 2017-04-15
        • 1970-01-01
        相关资源
        最近更新 更多