【发布时间】:2019-02-13 16:59:28
【问题描述】:
问题:如何在自定义 MATLAB 颜色栏中指定颜色转换?
具体来说,我想让黄色(见下文)覆盖更多颜色条的区域(可能是 [19.5–21.5] 或类似的东西)。
使用this answer,我能够在 MATLAB 中创建自定义颜色条。我试图理解this answer,因为它可能是相关的。
我尝试了this answer 的方法并查看了this answer 和this one,但无法实现我的目标。
很明显我遗漏了一些东西。
以下完整的代表性示例
% MATLAB 2017a
% Data
X = [22.6 22.8 22.6 20.45 22.3 18.15 19.95 20.8].';
Y = [84 89 63 81 68 83 77 52].';
Z = [23.0 22.695 21.1450 21.5 22.09 20.5 22.075 20.915].';
% Create custom colormap
% Reference: https://stackoverflow.com/questions/24488378/how-to-map-a-specific-value-into-rgb-color-code-in-matlab/24488819#24488819
col3 = [0 1 0]; %G
col2 = [1 1 0]; %Y
col1 = [1 0 0]; %R
n1 = 20; n2 = 20;
cmap=[linspace(col1(1),col2(1),n1);linspace(col1(2),col2(2),n1);linspace(col1(3),col2(3),n1)];
cmap(:,end+1:end+n2)=[linspace(col2(1),col3(1),n2);linspace(col2(2),col3(2),n2);linspace(col2(3),col3(3),n2)];
cmap = cmap.';
% Plot
colormap(cmap), hold on, box on
p = scatter(X,Y,[],Z,'filled','DisplayName','Data3');
cb = colorbar;
cb.Limits = [18 23];
cb.Ticks = [18:1:23];
% Cosmetics
p.MarkerEdgeColor = 'k';
xlabel('X')
ylabel('Y')
cb.Label.String = 'Z';
【问题讨论】:
标签: matlab plot matlab-figure scatter-plot colorbar