Alec
Alec

Reputation: 117

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?

Upvotes: 2

Views: 6140

Answers (2)

Amro
Amro

Reputation: 124563

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

screenshot

Refer to these pages for further explanations...

Upvotes: 2

Simon
Simon

Reputation: 32893

You have to have ZTick matching your ZTickLabel:

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

Upvotes: 1

Related Questions