variable Xtick on bar graph
1 view (last 30 days)
Show older comments
hello everyone,
i have this problem: i want to plot on bar figure infomation and wirth below this data the date of any column on the bar. the problem is that the user can choose differnt length of time to see one the graph and its causing to problam (many dates on the Xtick wirte one on the other and think like that). i tried to set that if the user choose more than 8 days so the Xtick will write only 8 days but with proportion between them (for exemple if he choose 16 day so it shoe the dates with jump of 2 days between a couple) but i having trouble to get the right string fo the Xtick. anyone can help? you can see what i done so far to maybe understand better my problem. thanks!
Labels = cellstr(Dates);
NumOfDates = length(Labels);
if NumOfDates < 7
set(gca,'XTick', 1 : NumOfDates, 'XTickLabel', Labels);
else
Labels(1) = Dates(1);
Labels(8) = Dates(end);
j = 2;
for i = 1 + round(NumOfDates/8) : round(NumOfDates/8) : NumOfDates
Labels(j) = Dates(i);
j = j + 1;
end
if strcmp(Labels(end), Labels(end - 1))
Labels(end - 1) = Dates(round(length(Dates) - (NumOfDates/8)));
end
set(gca,'XTick', 1 : (NumOfDates/8): NumOfDates, 'XTickLabel', Labels);
end
labels is the dates string to Xtick. * "Dates" its all the dates of the dtat and from this variable i need to peek max 8 dates.
0 Comments
Answers (1)
Walter Roberson
on 10 Apr 2016
I suggest you use linspace(1, NumOfDates, 8), possibly rounding the results.
3 Comments
Walter Roberson
on 10 Apr 2016
Index the Dates at the rounded index.
Or, if the dates are equally spaced and there are no holes, then you can linspace() the numeric equivalents of the dates.
See Also
Categories
Find more on Time Series Objects 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!