开发者

matlab axis to percent

I have an axis on a 3D plot which I would like to plot in percent. Currently, the values are decimals. So for example, I would like 0.12 to be displayed as '12%'.

Currently, I am using:

  temp_zlabels=100*str2num(get(gca,'ZTickLabel'));
  set(gca, 'ZTickLabel', sprintf('%开发者_开发百科d%%|', temp_zlabels))

This works fine, but when make the chart bigger or rotate it, the axis values start over, instead of re-scaling.

So for example, if I have an axis (0% 25% 50% 75%), and I make the graph bigger, the axis now reads (0% 25% 50% 75% 0% 25% 50% 75%) instead of correctly re-scaling the original axis.

What is the best way to label the axis in percent, where I do not run into this problem?


You have to fix the z-ticks positions:

set(gca, 'ZTickMode','manual')

Example:

D = rand(100,3);
plot3(D(:,1),D(:,2),D(:,3),'o'), box on, grid on
xlabel x, ylabel y, zlabel z

set(gca, 'ZTickMode','manual')
set(gca, 'ZTickLabel',num2str(100.*get(gca,'ZTick')','%g%%'))
rotate3d on

matlab axis to percent

Refer to these pages for further explanations...


You have to have ZTick matching your ZTickLabel:

set(gca, 'ZTick', temp_zlabels/100)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜