How do I change the number of ticks in matlab histogram and change axis numbers font size -
i want
- the
x-axis
display 1 2 3 4 5 6 - the
y-axis
display 0 20 40 60 80 100 - change numbers font size 14
i've tried setting different axis property
(ref. commented lines of code in script below) none of them affect graph.
%code generate dicesum dicesum = mydiceroller(1,500); figure(1) %create histogram hist(dicesum,ndice*6) %label axes xlabel('value of roll','fontsize',16) ylabel('number of times rolled','fontsize',16) %set(gca,'x','fontsize',14) %set(gca,'yticklabel',{'0' ;'100'}) %set('xtick','fontsize',14) %set('xlim',[0,6], 'ylim',[0 ,100]) %set('xtick',[0:1:6],'ytick',[0:20:100]) %set(gca,'xlim',[0 6]) %set(gca,'xtick',[0 1 2 3 4 5 6]) %set(gca,'xticklabel',str2mat{'0','1','2','3','4','5','6') %xlim([0 6])
this separate function i'm using create data , histogram
function [dicesum] = mydiceroller(ndice,nrolls) dicesum = zeros(1,nrolls);% = 1:nrolls;% on roll 1...roll 2 j = 1:ndice;% on roll 1 , roll #s of die n = ceil(rand(1)*6); dicesum(1,i) = dicesum(1,i) + n; end hist(dicesum,ndice*6) xlabel('value of roll') ylabel('number of times rolled') end
to have x-axis
displaying 1 2 3 4 5 6
have 2 possibilities:
to change way call
hist
function follows:% hist(dicesum,1:ndice*6)
hist(dicesum,1:6)
this because in call hist
2 parameters, second 1 should vector, in case, hist
returns distribution of y among length(x) bins centers specified x (being x
second parameter) - r2012b hist help
to directly set x-axis
xtick
follows:set(gca,'xtick',[0:6])
to have y-axis
displaying 0 20 40 60 80 100
have set y-axis ytick
follows:
set(gca,'ytick',[0:20:100])
to change x
, y
axis tick font size 14 have set axis fontsize
follows:
set(gca,'fontsize',14)
hope helps.
Comments
Post a Comment