Legend does not match with the bar chart in MATLAB
Show older comments
Hello,
I have a bar chart in Matlab. and I have changed every 24 bar to the same color. For example, the first 24 of them to the red, the second 24 of them to the blue, the third 24 of them to green, and the fourth 24 of them to black, but the color of the legend is incorrect and does not match with my plot. Here is my code:
data_kind2=xlsread('kind2.xlsx');
colors={'r','g','b','k'};
figure();
hold on
bar(data_kind2)
for ii=0:3
bar(ii*24+(1:24),data_kind2(ii*24+(1:24)),'FaceColor',colors{ii+1})
end
legend('Summer','Autumn','Winter','Spring');
set(gca,'Xtick',1:1:96,'XTickLabel',{'Evapotranspiration Deforestation Areas','Evapotranspiration Forest Areas','Evapotranspiration Transition Areas',...
'Soil moisture Deforestation Areas','Soil moisture Forest Areas','Soil moisture Transition Areas',...
'Air Temperature Deforestation Areas','Air Temperature Forest Areas','Air Temperature Transition Areas',...
'Total Runoff Deforestation Areas','Total Runoff Forest Areas','Total Runoff Transition Areas',...
'Sensible Heat Flux Deforestation Areas','Sensible Heat Flux Forest Areas','Sensible Heat Flux Transition Areas',...
'Soil Temperature Deforestation Areas','Soil Temperature Forest Areas','Soil Temperature Transition Areas',...
'ET/P Deforestation Areas','ET/P Forest Areas','ET/P Transition Areas','R/P Deforestation Areas','R/P Forest Areas','R/P Transition Areas',...
'Evapotranspiration Deforestation Areas','Evapotranspiration Forest Areas','Evapotranspiration Transition Areas',...
'Soil moisture Deforestation Areas','Soil moisture Forest Areas','Soil moisture Transition Areas',...
'Air Temperature Deforestation Areas','Air Temperature Forest Areas','Air Temperature Transition Areas',...
'Total Runoff Deforestation Areas','Total Runoff Forest Areas','Total Runoff Transition Areas',...
'Sensible Heat Flux Deforestation Areas','Sensible Heat Flux Forest Areas','Sensible Heat Flux Transition Areas',...
'Soil Temperature Deforestation Areas','Soil Temperature Forest Areas','Soil Temperature Transition Areas',...
'ET/P Deforestation Areas','ET/P Forest Areas','ET/P Transition Areas','R/P Deforestation Areas','R/P Forest Areas','R/P Transition Areas' 'Evapotranspiration Deforestation Areas','Evapotranspiration Forest Areas','Evapotranspiration Transition Areas',...
'Soil moisture Deforestation Areas','Soil moisture Forest Areas','Soil moisture Transition Areas',...
'Air Temperature Deforestation Areas','Air Temperature Forest Areas','Air Temperature Transition Areas',...
'Total Runoff Deforestation Areas','Total Runoff Forest Areas','Total Runoff Transition Areas',...
'Sensible Heat Flux Deforestation Areas','Sensible Heat Flux Forest Areas','Sensible Heat Flux Transition Areas',...
'Soil Temperature Deforestation Areas','Soil Temperature Forest Areas','Soil Temperature Transition Areas',...
'ET/P Deforestation Areas','ET/P Forest Areas','ET/P Transition Areas','R/P Deforestation Areas','R/P Forest Areas','R/P Transition Areas' 'Evapotranspiration Deforestation Areas','Evapotranspiration Forest Areas','Evapotranspiration Transition Areas',...
'Soil moisture Deforestation Areas','Soil moisture Forest Areas','Soil moisture Transition Areas',...
'Air Temperature Deforestation Areas','Air Temperature Forest Areas','Air Temperature Transition Areas',...
'Total Runoff Deforestation Areas','Total Runoff Forest Areas','Total Runoff Transition Areas',...
'Sensible Heat Flux Deforestation Areas','Sensible Heat Flux Forest Areas','Sensible Heat Flux Transition Areas',...
'Soil Temperature Deforestation Areas','Soil Temperature Forest Areas','Soil Temperature Transition Areas',...
'ET/P Deforestation Areas','ET/P Forest Areas','ET/P Transition Areas','R/P Deforestation Areas','R/P Forest Areas','R/P Transition Areas'});
set(gca,'XTickLabelRotation',90)
title('Relative Change v.s Monthly water balance in Deforestation,Forest, and Transition areas');
ylabel('Relative Change <%>')
xlabel('Monthly water balance');
grid on
Could anybody help me? I would really appreciate it if You help me.
Accepted Answer
More Answers (0)
Categories
Find more on Just for fun in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!