Effacer les filtres
Effacer les filtres

Force 0 tick to appear in a scatter plot

5 vues (au cours des 30 derniers jours)
Dimitrios Anagnostou
Dimitrios Anagnostou le 26 Jan 2023
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).

Réponse acceptée

Les Beckham
Les Beckham le 26 Jan 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 commentaires
Les Beckham
Les Beckham le 26 Jan 2023
Modifié(e) : Les Beckham le 26 Jan 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 le 26 Jan 2023
Very useful comment. Thanks again. I did the correction!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by