Force 0 tick to appear in a scatter plot

3 visualizzazioni (ultimi 30 giorni)
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).

Risposta accettata

Les Beckham
Les Beckham il 26 Gen 2023
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 Commenti
Les Beckham
Les Beckham il 26 Gen 2023
Modificato: Les Beckham il 26 Gen 2023
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 il 26 Gen 2023
Very useful comment. Thanks again. I did the correction!

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by