无法为每个子图设置不同的颜色图

Cannot set a different colormap for each subplot

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

注意:最近我把我的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;

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

colormap gray

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

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

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

colormap map sets the colormap for the current figure to one of the predefined colormaps. If you set the colormap for the figure, then axes and charts in the figure use the same colormap.

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

colormap(sx3, gray);

一些其他注意事项:

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

    f2 = figure('WindowState', 'maximized');
    
  • 当您已经有了坐标轴句柄 (sx1...3) 时,无需执行 ax = gca