【问题标题】:Making colorbar tick labels a string above and below bar, remove ticks - Matlab使颜色条刻度线在条形上方和下方标记一个字符串,删除刻度 - Matlab
【发布时间】:2019-04-06 11:39:21
【问题描述】:

我正在尝试为我的图表重现下面的颜色条。具体来说,我正在努力解决的是字符串颜色条轴标题(颜色条上方和下方),其余的似乎都很好。

以下是我当前的代码:

    time_begin  = [1981, 1, 1, 0,0,0];
    time_end    = [2010,12,31,23,0,0];
    years       = (time_begin(1):time_end(1))';
    nyears      = length(years);
    TXx1 = randi(100, 288, 192, 30);
    lat = rand(192, 1);
    lon = rand(288, 1);
    time = rand(30,1);
    M = numel(lon);
    N = numel(lat);
    slope1 = zeros(M, N);
    intercept1 = zeros(M, N);
    T = numel(time);
    x = ([ones(T, 1) years]);
    for i = 1 : M
        for j = 1 : N
            y1 = squeeze(TXx1(i, j, :));
            c = regress(y1, x);
            intercept1(i, j) = c(1);
            slope1(i, j) = c(2);      
        end
    end
    TXx2 = randi(100, 288, 192, 30);
    slope2 = zeros(M, N);
    intercept2 = zeros(M, N);
    T = numel(time);
    x = ([ones(T, 1) years]);
    for i = 1 : M
        for j = 1 : N
            y2 = squeeze(TXx2(i, j, :));
            c = regress(y2, x);
            intercept2(i, j) = c(1);
            slope2(i, j) = c(2);      
        end
    end
    figure()
    set(gcf, 'color', 'w'); 
    temp = [slope1(:) slope2(:)];
    temp(temp == 0) = NaN;
    [Q,Qc] = hist3(temp,'Nbins',[100 100],'CDataMode','auto');
    Qx = cell2mat(Qc(1));
    Qy = cell2mat(Qc(2));
    Q = Q';
    Q = Q./trapz(Qy,trapz(Qx,Q,2));
    surf(Qx,Qy,Q,'FaceColor','interp','EdgeColor','none')
    grid off
    set(gca, 'Fontsize', 12, 'Fontweight', 'Bold'); %added
    cmap = jet(500);
    cmap(1,:) = [1,1,1];
    colormap(cmap);
    h=colorbar;
    set(h,'position',[.91 .34 .031 .475]) %[xposition yposition width height].
    set(get(h,'ylabel'),'string','Point density'); 
    set(h,'XTickLabel',{'Low',' ',' ',' ',' ','High',}); 
    view(0,90)

这是我当前的颜色条:

【问题讨论】:

    标签: matlab plot gradient axis colorbar


    【解决方案1】:

    替换这一行:

    set(h,'XTickLabel',{'Low',' ',' ',' ',' ','High',}); 
    

    与:

    h.YTick = h.Limits;
    h.YTickLabel = {'Low', 'High'};
    

    这会产生两条刻度线和两个刻度标签。通过将颜色条的 YTicks 设置为其限制,刻度线与颜色条边界重叠。所以这些被隐藏了,现在不需要删除它们。
    但是有这个TickLength 属性可以在其他情况下使用,即

    h.TickLength = 0;
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-05
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2016-06-14
      • 2020-02-18
      相关资源
      最近更新 更多