How to have grayscale and rainbow color plots in subplots?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a MATLAB code snippet that uses subplot to generate some plots in the same figure. However, I want to make surf plots in subplot(3,3,2), subplot(3,3,5), subplot(3,3,8) colorful instead of grayscale and keep subplot(1,3,1), subplot(3,3,3), subplot(3,3,6), subplot(3,3,9) grayscale. How can I achieve that?
img = imread('moon.tif');
subplot(1,3,1);
imagesc(img);
colormap(gray);
title('moon.tif');
axis tight; axis equal;
subplot(3,3,2);
sigma = 3;
gaussianfilter = fspecial('gaussian', [90,90], sigma); % typically we would choose to filter width to be six times sigma
surf(gaussianfilter);
title(['Gaussian filter \sigma = ', num2str(sigma)]);
subplot(3,3,3);
img_filtered = conv2(img, gaussianfilter, 'same');
imagesc(img_filtered);
title('Filtered image');
axis tight; axis equal;
subplot(3,3,5);
sigma = 9;
gaussianfilter = fspecial('gaussian', [90,90], sigma);
surf(gaussianfilter);
title(['Gaussian filter \sigma = ', num2str(sigma)]);
subplot(3,3,6);
img_filtered = conv2(img, gaussianfilter, 'same');
imagesc(img_filtered);
title('Filtered image');
axis tight; axis equal;
subplot(3,3,8);
sigma = 15;
gaussianfilter = fspecial('gaussian', [90,90], sigma);
surf(gaussianfilter);
title(['Gaussian filter \sigma = ', num2str(sigma)]);
subplot(3,3,9);
img_filtered = conv2(img, gaussianfilter, 'same');
image(img_filtered);
title('Filtered image');
axis tight; axis equal;
0 Commenti
Risposta accettata
Dave B
il 9 Ott 2021
Modificato: Dave B
il 9 Ott 2021
You can pass in an axes to the colormap function, and you can get the axes from subplot. Just use the gray colormap for the ones you want in grayscale, and whatever non-gray colormap (or leave the default, parula) for the remainder.
ax1=subplot(2,2,1);
surf(peaks)
colormap(ax1,'turbo')
shading flat
ax2=subplot(2,2,2);
surf(peaks)
colormap(ax2,'gray')
shading flat
ax3=subplot(2,2,3);
surf(peaks)
colormap(ax3,'copper')
shading flat
ax4=subplot(2,2,4);
surf(peaks)
colormap(ax4,'hot')
shading flat
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Subplots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!