overtop IMAGESC text and change colorbar colors in white for some value of the text

1 visualización (últimos 30 días)
Hi guys!
This is how I get this graph, which shows the power values through the colormap , and on the same grid it overtop a text which represents the probability occurance , which is simply a matrix transormed in a character vector and overtop to the same graph.
% Grid
[X,Y]=meshgrid(Hs_x,Tp_y);
% Plot grid
figure;
h=imagesc(X(1:0.5:end),Y(1:1:end),Pw')
title('Wave power chart [kW]', 'FontSize',18);
xlabel('Hs [m]');ylabel('Tp [s]');
set(gca,'YDir','normal');
grid on;
set(gca,'xtick', linspace(Hs_x(1)-0.25,Hs_x(end)+0.25,length(Hs_x)+1),'ytick', linspace(Tp_y(1)-0.5,Tp_y(end)+0.5,length(Tp_y)+1));
set(gca,'xgrid', 'on', 'ygrid', 'on', 'gridlinestyle', '-', 'xcolor', 'k', 'ycolor', 'k');
%Text
txt=sprintfc('%.1f%%',f'*100);
text(X(:),Y(:),txt,'horizontalalignment','center','verticalalignment','middle','Color','black')
a=colorbar
a.Ticks = [0 0.1 50:100:850]
ylabel(a,'[kW]')
hColourbar.Label.Position(1) = 3
I would like to create white squares when the probability 'f' i equal to 0%. It means that in every square, where the value of probability matrix is equal to 0% , the square of the plot must be white. Any clue?
PLS, help
thank you

Respuestas (1)

Adam Danz
Adam Danz el 5 de Mzo. de 2021
The 0.0% values are rounded to 1dp so any values between -0.049 and 0.049 will show 0.0%. So, you need to find the indices of f that are within that range and then set the corresponding values in Pw to NaN. Then set the first value of your colormap to white using ax.Colormap(1,:)=[1,1,1];where ax is the axis handle.

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by