How to change the numbering system in the y axis? pitcure inside

2 次查看(过去 30 天)
Hi
I am new user to Matlab. I have 2 million entries and want to plot them as histogram. The problem I am getting the figure as the one attached where you can notice the y axis start from 0*10^5,0.5*10^5, ..... where I want it like: 1*10^5,2*10^5.... I want the y axis appear like the second picture.
<</matlabcentral/answers/uploaded_files/14594/Untitled.jpg
>>
here is the code I am using:
mydata1=load('data_m256_k5_n37.txt');
pp=hist(mydata1(:,1),max(mydata1(:,1))-min(mydata1(:,1))+1);
figure(1)
bar(min(mydata1(:,1)):max(mydata1(:,1)),pp,'w', 'LineWidth',2)
grid on
xlabel('\rho','FontSize',12)
ylabel('','FontSize',12)

回答(4 个)

Sara
Sara 2014-6-24
I can't see Fig 2 but I think you can rescale the yaxis and the replace the y-ticks if you want the exponent close to each tick:
xx = pp/1e5;
bar(min(mydata1(:,1)) : max(mydata1(:,1)),xx,'w', 'LineWidth',2)
yt = get(gca,'ytick')
ytstr = cell(numel(yt),1);
for i = 1:numel(yt)
ytstr{i} = [num2str(yt(i)),char(215),'10^5'];
end
set(gca,'YTicklabel',ytstr)

Bander
Bander 2014-6-24
Thanks for your reply here are the two figures. I want the y axis in fig 1 displayed as same as fig2.

Bander
Bander 2014-6-24
In the first figure y axis start with 0, 0.5, 1, 1.5, 2, 2.5,3)x 10e5 Wereas I want them to exactly as the secound figure. i now the valuse are same but the way they reprsnred is diffrent. The same code above some times gives me y axis like the second figure which is good. But other times it gives me like the first figure but diffrent valuse. I am not sure what should I add to the code to force matlab to represnt the y axis as in figure 2.
Thanks

Ben11
Ben11 2014-6-24
Maybe this:
set(gca,'YTick', 0:1E5:8E5);

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by