【问题标题】:Cannot set a different colormap for each subplot无法为每个子图设置不同的颜色图
【发布时间】:2018-08-10 12:24:59
【问题描述】:

我的代码中的颜色图函数应该为 3 个子图提供 3 个不同的颜色图。自去年以来,我一直在使用polarmap 颜色图来显示多普勒轮廓。我刚刚发现它不再工作了!所有三个子图现在都在同一个颜色图中,这是第一个:“热”。

注意:最近我将我的 MATLAB 从 2017 年更新到 2018 年。我不确定它是否会导致这样的错误。

下面是我的代码:

% Intensity, Doppler, Line width
f2 = figure();
set(f2,'position', [0, 0, screenX, screenY])

sx1 = subplot(1,3,1);
imagesc(x,t,(meanxytint'))
set(gca,'YDir','normal')
colormap hot
colorbar
caxis([0 5000])

xlabel('Solar X','FontSize',14,'FontWeight','bold')
ylabel('Solar Y','FontSize',14,'FontWeight','bold')
title('Intensity (DN)', 'FontSize', 16);
ax = gca;
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;

sx2 = subplot(1,3,2);
imagesc(x,t,meanxytdop')
set(gca,'YDir','normal')
colormap (sx2, flipud(polarmap(1024)))
colorbar
caxis([-100 100])

xlabel('Solar X','FontSize',14,'FontWeight','bold')
ylabel('Solar Y','FontSize',14,'FontWeight','bold')
title('Doppler Profile (km/s)', 'FontSize', 16);
ax = gca;
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;

sx3 = subplot(1,3,3);
imagesc(x,t,meanxytwid')
set(gca,'YDir','normal')
colormap gray
colorbar
caxis([0 150])

xlabel('Solar X','FontSize',14,'FontWeight','bold')
ylabel('Solar Y','FontSize',14,'FontWeight','bold')
title('Non-thermal Cont. (km/s)', 'FontSize', 16);
ax = gca;
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;

【问题讨论】:

  • 你能添加一些虚拟数据来提供minimal reproducible example吗?另外,您是说这不是在 2017 年发生,而是在 2018 年发生?

标签: matlab plot matlab-figure subplot colormap


【解决方案1】:

你的代码的问题是这一行:

colormap gray

请注意,在前两个轴中,您使用轴句柄来设置颜色图,例如

colormap (sx2, flipud(polarmap(1024)))

来自documentation of colormap(强调我的):

colormap map 将当前的颜色图设置为预定义的颜色图之一。如果为图窗设置颜色图,则图中的轴和图表使用相同的颜色图

修复很简单,只需使用与其他情况相同的语法即可:

colormap(sx3, gray);

其他一些注意事项:

  • 如果你想最大化你的身材,那么做

    f2 = figure('WindowState', 'maximized');
    
  • 如果您已经拥有坐标区句柄 (sx1...3),则无需执行 ax = gca

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 2019-12-01
    • 1970-01-01
    • 2019-03-04
    • 1970-01-01
    • 2021-05-22
    相关资源
    最近更新 更多