How to use bluewhitered function?
Afficher commentaires plus anciens
The bluewhitered function is a very used map plotting function. I want to know how to add limits, and how to set the center of the map. For example, if I want to plot a map with a range of [1,3], how to set the 2 to be the center and to be white?
1 commentaire
Walter Roberson
le 7 Mar 2019
caxis()
Réponse acceptée
Plus de réponses (1)
Yogesh Kumkar
le 5 Mar 2022
0 votes
I have tested the function. The figure 1 is wrong because -10 is NaN (gray). The figure 2 is correct but when I save it, I get NaN as white. Please suggest how to fix it.
Z=randi(10,5);
Y=randi([-10 10],5);
Z([2,10,13,24])=nan;Y([3,12,23])=nan;
figure(2); % first method: wrong
ax11=subplot(1,2,1);imagesc(Z);caxis([-10 10]);
cmap11=colormap(ax11,bluewhitered(22));
cmap11(1,:) = [0.5 0.5 0.5];
colormap(ax11,cmap11); h11=(colorbar);
ax12=subplot(1,2,2);imagesc(Y);caxis([-10 10]);
cmap12=colormap(ax12,bluewhitered(22));
cmap12(1,:) = [0.5 0.5 0.5];
colormap(ax12,cmap12); h12=(colorbar);
sgtitle('Figure 1 (cmap(1,:)=[0.5 0.5 0.5])','fontweight','bold','fontsize',16);
saveas(gcf,'/Volumes/YKMac/PAPER_3/Figures_P3/zTestNaN1.png');
%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
figure(3); % second method: correct
subplot(1,2,1);h3=imagesc(Z);caxis([-10 10]);
set(h3,'alphadata',~isnan(Z));
set(gca,'color', [0.5 0.5 0.5]);
colormap(bluewhitered(22)); colorbar; hold on;
subplot(1,2,2);h4=imagesc(Y);caxis([-10 10]);
set(h4,'alphadata',~isnan(Y));
set(gca,'color', [0.5 0.5 0.5]);
colormap(bluewhitered(22)); colorbar; hold on;
sgtitle('Figure 2 (set alphadata ~isnan(Y))','fontweight','bold','fontsize',16);
saveas(gcf,'/Volumes/YKMac/PAPER_3/Figures_P3/zTestNaN2.png');


2 commentaires
This is a common problem when trying to rely on the axes background color. Make sure to unset the 'inverthardcopy' property of the figure.
Z=randi(10,5);
Y=randi([-10 10],5);
Z([2,10,13,24])=nan;Y([3,12,23])=nan;
% second method: correct
subplot(1,2,1);h3=imagesc(Z);caxis([-10 10]);
set(h3,'alphadata',~isnan(Z));
set(gca,'color', [0.5 0.5 0.5]);
colormap(bluewhitered(22)); colorbar; hold on;
subplot(1,2,2);h4=imagesc(Y);caxis([-10 10]);
set(h4,'alphadata',~isnan(Y));
set(gca,'color', [0.5 0.5 0.5]);
colormap(bluewhitered(22)); colorbar; hold on;
sgtitle('Figure 2 (set alphadata ~isnan(Y))','fontweight','bold','fontsize',16);
% write the figure as a png
set(gcf,'inverthardcopy',false)
fname = 'zTestNaN2.png';
saveas(gcf,fname);
% read it back and display it
A = imread(fname);
clf
imshow(A)
Yogesh Kumkar
le 5 Mar 2022
set(gcf,'inverthardcopy',false)
works like a charm! Thanks.
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

