how to label x and y ticks?

1 回表示 (過去 30 日間)
Minka Califf
Minka Califf 2018 年 5 月 18 日
編集済み: Minka Califf 2018 年 5 月 19 日
I am trying to label my y axes to go from 1 to 50 by tens, and my x axes to have only 2 ticks labelled 'Morning' and 'Final'. I tried using set(gca,'YTick',1:10:50) but it's not working. Not sure what I'm doing wrong.
figure;
%%first plot
ax2 = subplot(1,2,1);
axis square;
ylabel('Odds');
%%second plot
subplot(1,2,2);
axis square;
% white background
set(gcf,'color','w');

採用された回答

dpb
dpb 2018 年 5 月 18 日
You don't show the code to generate the plot, but
ylim(ax1,[0 50])
ax1.Ytick=[1 10:50])
will work for the y-axes; of course the data itself will have to be in that range or it won't show up--such a mismatch is probably why what you've tried doesn't appear to work as you expect.
For the x-axes, you'll have to plot against two point values or use categorical variables
x=categorical({'Morning','Final'});
x=repmat(x,5,1);
y=(randi(50,5,2));
plot(x,y,'o')
ylim([0 50])
hAx=gca;
hAx.YTick=[1 10:10:50];
yields
for first crude approximation.
  2 件のコメント
Minka Califf
Minka Califf 2018 年 5 月 18 日
works great! Thanks!
dpb
dpb 2018 年 5 月 18 日
編集済み: dpb 2018 年 5 月 19 日
Oh, to keep ML from ordering the categorical variables by alphabetic order, use
x=categorical({'Morning','Final'},{'Morning','Final'});
to define the valueset order.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by