![How to change interval of x axis - 2019 05 08.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/218590/How%20to%20change%20interval%20of%20x%20axis%20-%202019%2005%2008.png)
How to change interval of x axis
27 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
maria serey-roman
il 8 Mag 2019
Commentato: Star Strider
il 8 Mag 2019
I have a graph plotting annual ridership vs years. When this is plotted, the interval in the x axis is increasing by 0.5. I need it to increase by 1, so that it's simply years 2011, 2012, 2013 and so forth. See code and picture.
Please advise.
%Cubic Spline w/ Knot-a-Not Condition
years = [2012 2013 2014 2015 2016 2017]; % x values
annual_ridership = [16.366669 16.864938 17.087795 17.224537 17.301839 17.095073]; % y values
xx = [2012:0.125:2017];
yy = spline(years, annual_ridership, xx);
plot(years,annual_ridership,'o', xx,yy)
title('Cubic Spline');
xlabel('Year');
ylabel('Annual Subway Ridership in millions')
grid
0 Commenti
Risposta accettata
Star Strider
il 8 Mag 2019
Modificato: Star Strider
il 8 Mag 2019
You can define the 'XTick' values:
plot(years,annual_ridership,'o', xx,yy)
set(gca, 'XTick',years) % <— ADD THIS LINE
That worked when I ran your code with this modification.
The complete code is then:
years = [2012 2013 2014 2015 2016 2017]; % x values
annual_ridership = [16.366669 16.864938 17.087795 17.224537 17.301839 17.095073]; % y values
xx = [2012:0.125:2017];
yy = spline(years, annual_ridership, xx);
plot(years,annual_ridership,'o', xx,yy)
set(gca, 'XTick',years) % <— ADD THIS LINE
title('Cubic Spline');
xlabel('Year');
ylabel('Annual Subway Ridership in millions')
grid
and the resulting figure:
![How to change interval of x axis - 2019 05 08.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/218590/How%20to%20change%20interval%20of%20x%20axis%20-%202019%2005%2008.png)
EDIT — Added plot image.
2 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!