Force 0 tick to appear in a scatter plot

조회 수: 3 (최근 30일)
Dimitrios Anagnostou
Dimitrios Anagnostou 2023년 1월 26일
댓글: Dimitrios Anagnostou 2023년 1월 26일
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
Dimitrios Anagnostou 2023년 1월 26일
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