How to remove space from beginning of a plot?
Show older comments
I have a plot with monthly data over multiple years, but there is a space in front of the plot that I would like to remove and start the X-axis limit from January (i.e., Jan Feb Mar Apr Oct Nov Dec).
T=table(datestr(Temp6ONDJFMAcorrect.DATE,'dd/mm/yyyy'),Temp6ONDJFMAcorrect.Temp);
[y,m,d] = datevec(T.Var1,'dd/mm/yyyy');
Tdate = table(y,m,d,'VariableName',{'year','month','day'});
TT = [Tdate,T(:,{'Var2'})];
TT.Properties.VariableNames{4} = 'Temp'; yrs = TT.year;
yr = ismember(str2double(string(TT.year)),yrs);
x = reshape(TT.month(yr),7,[]);
y = reshape(TT.Temp(yr),7,[]);
plot(x,y)
xticklabels({'Jan', 'Feb', 'Mar','Apr','Oct','Nov','Dec'})
4 Comments
Image Analyst
on 13 Feb 2023
Give us code to create "Temp6ONDJFMAcorrect"
Anwesha Sharma
on 13 Feb 2023
Image Analyst
on 13 Feb 2023
So is the missing line
Temp6ONDJFMA = readtable('Temp6ONDJFMA.xls'); % Read workbook file into a MATLAB table variable.
??? Anyway, it looks like you've accepted an answer so I guess it doesn't matter anymore since you've gotten a solution.
Anwesha Sharma
on 14 Feb 2023
Answers (1)
Alexander Halbleib
on 13 Feb 2023
Edited: Alexander Halbleib
on 13 Feb 2023
you may be able to try:
xlim([1,12]);
at the end of your file.
If I'm reading your code properly, your axes should be numeric, so this version should work.
1 Comment
Anwesha Sharma
on 14 Feb 2023
Edited: Anwesha Sharma
on 14 Feb 2023
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!