MATLAB Answers

how to add a label to a contourf plot next to colourbar?

조회 수: 2(최근 30일)
Tony Castillo
Tony Castillo 2021년 6월 2일
댓글: Tony Castillo 2021년 6월 3일
Hello mathcoders,
I want to add a label next to the colourbar for adding the variable's name, how can I do it?. The resulting plot and code is attached to these brief lines. Also I have noticed that when adding months labels it only present till June, but when remove the colourbar it prints till December, how can I solve this?.
Thanks in advance
irradiation_alongyear=[Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec];
ylabel('Hours of the day', 'Fontsize', 14)
title('Irradiation distribution along the year','FontSize',14)
  댓글 수: 2
Tony Castillo
Tony Castillo 2021년 6월 3일
I apologize for not sharing more data, I guess that it but be doable with the part of the code that I shared.

댓글을 달려면 로그인하십시오.

채택된 답변

Joseph Cheng
Joseph Cheng 2021년 6월 2일
편집: Joseph Cheng 2021년 6월 2일
you can set a ylabel by passing the colorbar handles into ylabel
[X,Y] = meshgrid(1:12,1:24);
Z = sin(X) + cos(Y);
lastname = {'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'};
ylabel('hours of the day')
xticks([1:12]);xlim([1 12]);
hbar = colorbar;
here essentially i generated a dummy set of data to contourf() then force the x limits to 1 to 12 for the month then set hbar as the colorbar handles such that ylabel() knows what to label
  댓글 수: 2
Tony Castillo
Tony Castillo 2021년 6월 3일
Thank you Sir Cheng, it worked properly.

댓글을 달려면 로그인하십시오.

추가 답변(0개)




Community Treasure Hunt

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

Start Hunting!

Translated by