Force 0 tick to appear in a scatter plot

3 次查看(过去 30 天)
I cannot make the 0 tick appear nomatter what I tried. Here is my code.
clc, clear, clf
n = 0:10; f = n.^2;
scatter(n,f, 'k', 'filled')
xlim([-1,11]), ylim([-10,120])
ax = gca;
ax.XAxisLocation = 'origin'; ax.YAxisLocation = 'origin';
ax.XTick = -2:2:10; ax.YTick = -20:20:120;
xlabel('n'), ylabel('f(n)=n^2')
title('Sequence f(n)=n^2')
grid on; grid minor
For the sake of clarity, I wanted the ticks in the origin to appear explicitly as in the following figure (the rest of the plot is irrelevant).

采纳的回答

Les Beckham
Les Beckham 2023-1-26
clc, clear, clf
n = 0:10; f = n.^2;
scatter(n,f, 'k', 'filled')
xlim([-1,11]), ylim([-10,120])
ax = gca;
ax.XAxisLocation = 'origin'; ax.YAxisLocation = 'origin';
ax.XTick = -2:2:10; ax.YTick = -20:20:120;
xlabel('n'), ylabel('f(n)=n^2')
title('Sequence f(n)=n^2')
grid on; grid minor
ax.XTickLabels = -2:2:10;
  3 个评论
Les Beckham
Les Beckham 2023-1-26
编辑:Les Beckham 2023-1-26
You are quite welcome.
ax.XTick sets the values of the axis at which you wish to have tick marks. ax.XTickLabel sets the strings (or char vectors) to be used as labels for those tick marks.
BTW - the title of your questions says "stem plot" but this is a scatter. Maybe you could change the title to avoid confusion for people reading this (or searching) in the future?
Dimitrios Anagnostou
Very useful comment. Thanks again. I did the correction!

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by