How to place figure labels

조회 수: 2(최근 30일)
wejdan Albanna
wejdan Albanna 2018년 4월 12일
댓글: dpb 2018년 4월 13일
I need to change the x-axis labels, and the following format I wrote is not working, any help!
x = [ 1.3404 1.3404 1.5011;
2.1141 2.1141 2.1591;
2.4665 2.4665 2.4935;
2.8187 2.8187 2.8591;
3.1711 3.1711 3.2464];
figure bar(x,'FaceColor','flat')
hold on
set(gca,'xticklabels')
xticklabels ({'5','5+1','5+2','5+3','5+4'})
xlabel('Number of Nodes')
ylabel('Total Power')
legend('CL1','CL2', 'CL3')
title('clusters')
hold off
  댓글 수: 3
dpb
dpb 2018년 4월 13일
Of course it only "lasts" for one figure; the tick labels are properties of the axes and are refreshed any time a new axes is created.
You don't want to set the default labels to something for a specific figure/plot; then you've essentially broken the PLOT() command for anything else without fixing it up every time.
Instead, if you're doing this multiple times, write a script or function that you execute/call for each case and include setting the tick labels appropriately in it. You do it once in writing the function but then it's done for you automagically when you use the function/script.
In general you would not hardcode text into the function but either derive the values for the labels from the data or pass in what is appropriate for the particular case; if this is processing a bunch of data for a very specific and narrow-scope kind of analysis then it could make sense for that purpose if number and text for the labels really won't ever change.

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

채택된 답변

Von Duesenberg
Von Duesenberg 2018년 4월 12일
Is this what you are trying to achieve ? :
x = [ 1.3404 1.3404 1.5011;
2.1141 2.1141 2.1591;
2.4665 2.4665 2.4935;
2.8187 2.8187 2.8591;
3.1711 3.1711 3.2464];
figure; bar(x,'FaceColor','flat')
set(gca,'xticklabels', {'5','5+1','5+2','5+3','5+4'})
xlabel('Number of Nodes')
ylabel('Total Power')
legend('CL1','CL2', 'CL3')
title('clusters')

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by