How to place figure labels

3 次查看(过去 30 天)
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 个评论
wejdan Albanna
wejdan Albanna 2018-4-13
I tried to change the labels in the x-axis, I did it previously using 'Figure Properties', but it only last for one figure. I am asking about the following code and what need to be rewritten/change
xticklabels ({'5','5+1','5+2','5+3','5+4'})
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 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by