Shah
Shah

Reputation: 23

Cannot set a different colormap for each subplot

The colormap function in my code should give 3 different colormaps for 3 subplots. I have been using the polarmap colormap since last year to show the Doppler profile. I've just discovered that it is not working anymore! All three subplots are now in same colormap which is the first one: "hot".

Note: Recently I updated my MATLAB from 2017 to 2018. I am not sure whether it may cause such error.

Below is my code:

% 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;

Upvotes: 2

Views: 817

Answers (1)

Dev-iL
Dev-iL

Reputation: 24159

The problem with your code is this line:

colormap gray

Note that in the first two axes you use the axes handle to set the colormap, e.g.

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

From the documentation of colormap (emphasis mine):

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.

The fix is easy, just use the same syntax as in the other cases:

colormap(sx3, gray);

Some other notes:

  • If you want to maximize you figure, do

    f2 = figure('WindowState', 'maximized');
    
  • There's no need to do ax = gca when you already have the axes handle (sx1...3).

Upvotes: 1

Related Questions