Hi,
I am trying to plot two data sets.
One of them ranges from -40:40 while the other ranges from -50:50.
The plots look fine when I use xlim([-40,40]) and show appropriate number of axis points on the x-axis.
However, when I use xlim([-50,50]), the plot only shows 3 points on x-axis. (please refer to the picture attached)
How can I show more points on x-axis when using xlim([-50,50]) ?
Thanks in advance.

 Réponse acceptée

Walter Roberson
Walter Roberson le 5 Mar 2020

1 vote

The plot is showing many points on the x axis.
What it is not showing is many ticks on the x axis.
When you do not specify the tick locations yourself, the plotting software tries to fill in "nice" ticks. It prefers multiples of 10, and then multiples of 5, and then multiples of 1. It has a lower bound on the number of nice tick locations, and it has an upper bound on the number of nice tick locations.
The multiples of 50 that are generated are multiples of 10 and 5 both, so they are favoured. Multiples of 10 as is used for the other plot are not as favored because of the number of ticks that would be generated.
If plot were to generate more then it would probably generate -50 -25 0 25 50.
You can resolve this by using xticks() to indicate exactly where you want the ticks to go.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by